public static List<SunDiskCondition> PredictSDC_NN(
            List<Tuple<SkyImageIndexesStatsData, ConcurrentData>> lTplInputData, IEnumerable<int> SDC_NNconfig,
            IEnumerable<double> SDC_NNtrainedParameters,
            IEnumerable<double> NNfeturesNormMeans, IEnumerable<double> NNfeaturesNormRange,
            out List<List<double>> decisionProbabilitiesList)
        {

            List<string> lImagesALLstatsDataCSVWithConcurrentData = lTplInputData.ConvertAll(tpl =>
            {
                SkyImageIndexesStatsData imageStats = tpl.Item1;
                ConcurrentData snapshotConcurrentData = tpl.Item2;
                return imageStats.ToCSV() + "," +
                       snapshotConcurrentData.gps.SunZenithAzimuth().ElevationAngle.ToString().Replace(",", ".") + "," +
                       snapshotConcurrentData.gps.SunZenithAzimuth().Azimuth.ToString().Replace(",", ".");
            });
            // string currImageALLstatsDataCSVWithConcurrentData = 

            string csvHeader = lTplInputData.First().Item1.CSVHeader() +
                               ",SunElevationDeg,SunAzimuthDeg,sunDiskCondition";

            List<string> lCalculatedData = new List<string>();
            // lCalculatedData.Add(currImageALLstatsDataCSVWithConcurrentData);
            lCalculatedData.AddRange(lImagesALLstatsDataCSVWithConcurrentData);

            List<List<string>> csvFileContentStrings =
                lCalculatedData.ConvertAll(str => str.Split(',').ToList()).ToList();
            List<string> lCSVheader = csvHeader.Split(',').ToList();

            List<int> columnsToDelete =
                lCSVheader.Select((str, idx) => new Tuple<int, string>(idx, str))
                    .Where(tpl => tpl.Item2.ToLower().Contains("filename")).ToList().ConvertAll(tpl => tpl.Item1);
            List<List<string>> csvFileContentStringsFiltered = new List<List<string>>();
            foreach (List<string> listDataStrings in csvFileContentStrings)
            {
                csvFileContentStringsFiltered.Add(
                    listDataStrings.Where((str, idx) => !columnsToDelete.Contains(idx)).ToList());
            }



            List<List<string>> csvFileContentStringsFiltered_wo_sdc = csvFileContentStringsFiltered;

            List<DenseVector> lDV_objects_features =
                csvFileContentStringsFiltered_wo_sdc.ConvertAll(
                    list =>
                        DenseVector.OfEnumerable(list.ConvertAll<double>(str => Convert.ToDouble(str.Replace(".", ",")))));


            DenseVector dvMeans = DenseVector.OfEnumerable(NNfeturesNormMeans);
            DenseVector dvRanges = DenseVector.OfEnumerable(NNfeaturesNormRange);
            DenseVector dvThetaValues = DenseVector.OfEnumerable(SDC_NNtrainedParameters);
            List<int> NNlayersConfig = SDC_NNconfig.ToList();

            lDV_objects_features = lDV_objects_features.ConvertAll(dv =>
            {
                DenseVector dvShifted = dv - dvMeans;
                DenseVector dvNormed = (DenseVector)dvShifted.PointwiseDivide(dvRanges);
                return dvNormed;
            });

            DenseMatrix dmObjectsFeatures = DenseMatrix.OfRowVectors(lDV_objects_features);




            List<List<double>> lDecisionProbabilities = null;

            List<SunDiskCondition> predictedSDClist =
                NNclassificatorPredictor<SunDiskCondition>.NNpredict(dmObjectsFeatures, dvThetaValues, NNlayersConfig,
                    out lDecisionProbabilities, SunDiskConditionData.MatlabEnumeratedSDCorderedList()).ToList();

            //List<SunDiskCondition> predictedSDClist =
            //    predictedSDC.ConvertAll(sdcInt => SunDiskConditionData.MatlabSDCenum(sdcInt));


            decisionProbabilitiesList = lDecisionProbabilities;
            return predictedSDClist;
        }
示例#2
0
        public static int PredictTCC_NN(SkyImageIndexesStatsData imageStats, ConcurrentData snapshotConcurrentData,
                                        IEnumerable <int> SDC_NNconfig, IEnumerable <double> SDC_NNtrainedParameters,
                                        IEnumerable <double> SDC_NNfeturesNormMeans,
                                        IEnumerable <double> SDC_NNfeaturesNormRange, IEnumerable <int> TCCnnLayersConfig,
                                        IEnumerable <double> TCC_NNtrainedParameters, IEnumerable <double> TCC_NNfeturesNormMeans,
                                        IEnumerable <double> TCC_NNfeaturesNormRange, IEnumerable <int> TCCnnConfigVarsToExclude,
                                        out List <double> TCCdecisionProbabilities)
        {
            string currImageALLstatsDataCSVWithConcurrentData = imageStats.ToCSV() + "," +
                                                                snapshotConcurrentData.gps.SunZenithAzimuth().ElevationAngle.ToString().Replace(",", ".") + "," +
                                                                snapshotConcurrentData.gps.SunZenithAzimuth().Azimuth.ToString().Replace(",", ".");

            List <string> lCalculatedData = new List <string>();

            lCalculatedData.Add(currImageALLstatsDataCSVWithConcurrentData);

            string        csvHeader       = imageStats.CSVHeader();
            List <string> lCSVheader      = csvHeader.Split(',').ToList();
            List <int>    columnsToDelete =
                lCSVheader.Select((str, idx) => new Tuple <int, string>(idx, str))
                .Where(tpl => tpl.Item2.ToLower().Contains("filename")).ToList().ConvertAll(tpl => tpl.Item1);


            List <List <string> > csvFileContentStrings =
                lCalculatedData.ConvertAll(str => str.Split(',').ToList()).ToList();
            List <List <string> > csvFileContentStringsFiltered = new List <List <string> >();

            foreach (List <string> listDataStrings in csvFileContentStrings)
            {
                csvFileContentStringsFiltered.Add(
                    listDataStrings.Where((str, idx) => !columnsToDelete.Contains(idx)).ToList());
            }

            #region SDC prediction

            List <List <string> > csvFileContentStringsFiltered_wo_CC = csvFileContentStringsFiltered;


            List <DenseVector> lDV_objects_features =
                csvFileContentStringsFiltered_wo_CC.ConvertAll(
                    list =>
                    DenseVector.OfEnumerable(list.ConvertAll <double>(CommonTools.ParseDouble)));
            DenseMatrix dmSDCpredictionObjectsFeatures = DenseMatrix.OfRows(lDV_objects_features);

            // DenseVector dvMeans = DenseVector.OfEnumerable(SDC_NNfeturesNormMeans);
            // DenseVector dvRanges = DenseVector.OfEnumerable(SDC_NNfeaturesNormRange);
            DenseMatrix dmSDCpredictionObjectsFeaturesNormed =
                ANNservice.FeatureNormalization(dmSDCpredictionObjectsFeatures, SDC_NNfeturesNormMeans,
                                                SDC_NNfeaturesNormRange);


            #region Predict SDC

            List <int>       sdcMatlabValues             = new List <int>();
            List <double>    lSDCpredictionProbabilities = new List <double>();
            SunDiskCondition sdc = SDCpredictorNN.PredictSDC_NN(imageStats, snapshotConcurrentData, SDC_NNconfig,
                                                                SDC_NNtrainedParameters, SDC_NNfeturesNormMeans, SDC_NNfeaturesNormRange, out lSDCpredictionProbabilities);
            sdcMatlabValues.Add(SunDiskConditionData.MatlabNumeralSDC(sdc));

            //lDV_objects_features = lDV_objects_features.Zip(sdcMatlabValues, (dv, intSDC) =>
            //{
            //    List<double> lFeaturesWithSDCdata = lDV_objects_features[0].ToList();
            //    lFeaturesWithSDCdata.Add((double)intSDC);
            //    return DenseVector.OfEnumerable(lFeaturesWithSDCdata);
            //}).ToList();

            #endregion Predict SDC

            #endregion SDC prediction

            DenseMatrix           dmTCCpredictionObjectsFeatures = dmSDCpredictionObjectsFeatures.Copy();
            List <List <double> > rowsSDCprobabilitiesPerObject  = new List <List <double> >();
            rowsSDCprobabilitiesPerObject.Add(lSDCpredictionProbabilities);
            DenseMatrix dmToAppend = DenseMatrix.OfRows(rowsSDCprobabilitiesPerObject);
            dmTCCpredictionObjectsFeatures = (DenseMatrix)dmTCCpredictionObjectsFeatures.Append(dmToAppend);

            // remove vars listed in TCCnnConfigVarsToExclude
            List <int> TCCnnConfigVarsToExcludeIndexes = TCCnnConfigVarsToExclude.ToList();
            TCCnnConfigVarsToExcludeIndexes = TCCnnConfigVarsToExcludeIndexes.ConvertAll(i => i - 1);           // based_1 indexes to based_0
            DenseMatrix dmTCCpredictionObjectsFeatures_RemovedExcludingFeatures =
                dmTCCpredictionObjectsFeatures.RemoveColumns(TCCnnConfigVarsToExcludeIndexes);


            DenseMatrix dmTCCpredictionObjectsFeatures_RemovedExcludingFeatures_Normed =
                ANNservice.FeatureNormalization(dmTCCpredictionObjectsFeatures_RemovedExcludingFeatures,
                                                TCC_NNfeturesNormMeans,
                                                TCC_NNfeaturesNormRange);


            List <List <double> > lTCCdecisionProbabilities = null;

            List <int> TCCvaluesSet = new List <int>();
            for (int i = 0; i < 9; i++)
            {
                TCCvaluesSet.Add(i);
            }
            List <int> predictedTCC =
                NNclassificatorPredictor <int> .NNpredict(dmTCCpredictionObjectsFeatures_RemovedExcludingFeatures_Normed,
                                                          TCC_NNtrainedParameters, TCCnnLayersConfig, out lTCCdecisionProbabilities, TCCvaluesSet).ToList();


            // Matlab trained TCC model: classes 1-9
            //predictedTCC = predictedTCC.ConvertAll(iVal => iVal - 1);

            TCCdecisionProbabilities = lTCCdecisionProbabilities[0];


            return(predictedTCC[0]);
        }