Skip to content
Snippets Groups Projects
Commit ff23a21c authored by bbauvin's avatar bbauvin
Browse files

Trying to fix segmentation fault

parent d055976e
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,6 @@ from sklearn.ensemble import RandomForestClassifier # RandomForest-Classifie ...@@ -13,7 +13,6 @@ from sklearn.ensemble import RandomForestClassifier # RandomForest-Classifie
import sklearn import sklearn
import numpy as np import numpy as np
import random import random
import scipy.sparse
# Import own modules # Import own modules
...@@ -59,14 +58,6 @@ def extractRandomTrainingSet(CLASS_LABELS, LEARNING_RATE, DATASET_LENGTH, NB_CLA ...@@ -59,14 +58,6 @@ def extractRandomTrainingSet(CLASS_LABELS, LEARNING_RATE, DATASET_LENGTH, NB_CLA
return trainingExamplesIndices return trainingExamplesIndices
def extractSet(X, usedIndices):
if scipy.sparse.issparse(X):
for index in usedIndices:
pass
else:
return X[usedIndices]
##### Generating Test and Train Data ##### Generating Test and Train Data
def calcTrainTestOwn(X,y,split): def calcTrainTestOwn(X,y,split):
......
...@@ -12,8 +12,7 @@ import operator ...@@ -12,8 +12,7 @@ import operator
# Import 3rd party modules # Import 3rd party modules
import numpy as np # for reading CSV-files and Series import numpy as np # for reading CSV-files and Series
import pandas as pd # for Series and DataFrames import pandas as pd # for Series and DataFrames
import logging import logging # To create Log-Files
from scipy import sparse # To create Log-Files
from sklearn import metrics # For stastics on classification from sklearn import metrics # For stastics on classification
import h5py import h5py
...@@ -23,7 +22,7 @@ import ExportResults # Functions to render results ...@@ -23,7 +22,7 @@ import ExportResults # Functions to render results
import MonoviewClassifiers import MonoviewClassifiers
import Metrics import Metrics
from analyzeResult import execute from analyzeResult import execute
from utils.Dataset import getV, getValue from utils.Dataset import getV, getValue, extractSubset
# Author-Info # Author-Info
__author__ = "Nikolas Huelsmann, Baptiste BAUVIN" __author__ = "Nikolas Huelsmann, Baptiste BAUVIN"
...@@ -72,9 +71,9 @@ def ExecMonoview(X, Y, name, learningRate, nbFolds, nbCores, databaseType, path, ...@@ -72,9 +71,9 @@ def ExecMonoview(X, Y, name, learningRate, nbFolds, nbCores, databaseType, path,
logging.debug("Start:\t Determine Train/Test split") logging.debug("Start:\t Determine Train/Test split")
testIndices = ClassifMonoView.splitDataset(Y, nbClass, learningRate, datasetLength) testIndices = ClassifMonoView.splitDataset(Y, nbClass, learningRate, datasetLength)
trainIndices = [i for i in range(datasetLength) if i not in testIndices] trainIndices = [i for i in range(datasetLength) if i not in testIndices]
print sparse.eye(347)*X
print "poulet" X_train = extractSubset(X,trainIndices) #ClassifMonoView.extractSet(X, trainIndices)
X_train = X[trainIndices]#ClassifMonoView.extractSet(X, trainIndices) testIndices = np.arange(100)
X_test = X[testIndices]#ClassifMonoView.extractSet(X,testIndices) X_test = X[testIndices]#ClassifMonoView.extractSet(X,testIndices)
y_train = Y[trainIndices] y_train = Y[trainIndices]
......
import h5py
from scipy import sparse from scipy import sparse
import numpy as np
def getV(DATASET, viewIndex, usedIndices=None): def getV(DATASET, viewIndex, usedIndices=None):
...@@ -29,3 +29,19 @@ def getValue(DATASET): ...@@ -29,3 +29,19 @@ def getValue(DATASET):
DATASET.get("indices").value, DATASET.get("indices").value,
DATASET.get("indptr").value), DATASET.get("indptr").value),
shape=DATASET.attrs["shape"]) shape=DATASET.attrs["shape"])
def extractSubset(matrix, usedIndices):
if sparse.issparse(matrix):
newIndptr = np.zeros(len(usedIndices)+1, dtype=np.int16)
oldindptr = matrix.indptr
for exampleIndexIndex, exampleIndex in enumerate(usedIndices):
if exampleIndexIndex>0:
newIndptr[exampleIndexIndex] = newIndptr[exampleIndexIndex-1]+(oldindptr[exampleIndex]-oldindptr[exampleIndex-1])
newData = np.ones(newIndptr[-1], dtype=bool)
newIndices = np.zeros(newIndptr[-1], dtype=np.int32)
oldIndices = matrix.indices
for exampleIndexIndex, exampleIndex in enumerate(usedIndices):
newIndices[newIndptr[exampleIndexIndex]:newIndptr[exampleIndexIndex]] = oldIndices[oldindptr[exampleIndex], oldindptr[exampleIndex+1]]
return sparse.csr_matrix((newData, newIndices, newIndptr), shape=(len(usedIndices), matrix.shape))
else:
return matrix[usedIndices]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment