Exemple #1
0
    public override void InitialiseFeatures(
        DatasetName datasetName,
        object[,] x,
        object[] y)
    {
        Debug.Assert(x != null, "The feature vector must not be null.");
        Debug.Assert(y != null, "The targe variable must not be null.");
        Vector[] xV = null;
        Range    r  = null;

        // Validate
        _validate.Dataset(
            labels: _mapping.GetClassLabels().ToArray(),
            datasetName: datasetName,
            x: x,
            y: y);

        // Set meta data
        _numFeatures     = x.GetLength(0);
        _numObservations = x.GetLength(1);

        // Transpose
        double[][] xTrans = new double[_numObservations][];

        for (int j = 0; j < _numObservations; j++)
        {
            xTrans[j] = new double[_numFeatures];
            for (int i = 0; i < _numFeatures; i++)
            {
                xTrans[j][i] = (double)x[i, j];
            }
        }

        // Set target
        _y = Variable.Observed(
            Array.ConvertAll(y, v => (
                                 System.Convert.ToInt64(v) > 0) ? true : false)).Named(
            "y." + datasetName.ToString());

        // Set features
        xV = new Vector[_numObservations];
        r  = _y.Range.Named("person");
        for (int i = 0; i < _numObservations; i++)
        {
            xV[i] = Vector.FromArray(xTrans[i]);
        }
        _x = Variable.Observed(xV, r).Named("x." + datasetName.ToString());

        _availableDatasetName = datasetName;
    }
Exemple #2
0
    public override void InitialiseFeatures(
        DatasetName datasetName,
        object[,] x,
        object[] y)
    {
        Debug.Assert(x != null, "The feature vector must not be null.");
        Debug.Assert(y != null, "The targe variable must not be null.");

        // Validate
        _validate.Dataset(
            labels: _mapping.GetClassLabels().ToArray(),
            datasetName: datasetName,
            x: x,
            y: y);

        // Set meta data
        _numFeatures     = x.GetLength(0);
        _numObservations = x.GetLength(1);

        // Transpose
        double[][] xTrans = new double[_numObservations][];

        for (int j = 0; j < _numObservations; j++)
        {
            xTrans[j] = new double[_numFeatures];
            for (int i = 0; i < _numFeatures; i++)
            {
                xTrans[j][i] = (double)x[i, j];
            }
        }

        // Set target
        _y = new List <string>(
            Array.ConvertAll(y, v => v.ToString()));

        // Set features
        _x = new Vector[_numObservations];
        for (int i = 0; i < _numObservations; i++)
        {
            _x[i] = Vector.FromArray(xTrans[i]);
        }

        _availableDatasetName = datasetName;
    }