Exemple #1
0
        public RegressionResult PerformRegression(MergedBacteria bacteria)
        {
            var trainSize = (int)(bacteria.Bacterium1.Measurements.Count() / 100.0 * TrainSizePercentage);
            var trainX    = bacteria.Bacterium1.Measurements.Take(trainSize).ToArray();
            var testX     = bacteria.Bacterium1.Measurements.Skip(trainSize).ToArray();

            var trainY = bacteria.Bacterium2.Measurements.Take(trainSize).ToArray();
            var testY  = bacteria.Bacterium2.Measurements.Skip(trainSize).ToArray();

            var result = RegressionModel.PerformRegression(trainX, trainY, testX, testY);

            result.TrainX = trainX;
            result.TrainY = trainY;
            result.TestX  = testX;
            result.TestY  = testY;
            result.Error  = new SquareLoss(trainX).Loss(result.PredictionOnTrainingSet);
            return(result);
        }
Exemple #2
0
        public static MergedBacteria MergeBacteria(Bacterium b1, Bacterium b2)
        {
            var merged = new MergedBacteria()
            {
                Bacterium1 = b1,
                Bacterium2 = b2
            };

            merged.Points = new List <Tuple <double, double> >();
            for (var i = 0; i < b1.Measurements.Count; i++)
            {
                merged.Points.Add(new Tuple <double, double>(b1.Measurements[i], b2.Measurements[i]));
            }

            merged.CosineDistance      = 1 - Distance.Cosine(b1.Measurements.ToArray(), b2.Measurements.ToArray());
            merged.SpearmanCorrelation = Correlation.Spearman(b1.Measurements, b2.Measurements);
            merged.PearsonCorrelation  = Correlation.Pearson(b1.Measurements, b2.Measurements);

            return(merged);
        }