public static ModelParent getTrainedModel(string trainPointsFileName, TrainPointsList trainPoints, Type method) { if (method == typeof(ModelParent)) return ModelParent.getModel(trainPoints); if (method == typeof(LeastSquaresModel_MinMax)) return LeastSquaresModel_MinMax.getModel(trainPointsFileName); if (method == typeof(LeastSquaresModel)) return LeastSquaresModel.getModel(trainPoints); if (method == typeof(KNNModel)) return KNNModel.getModel(trainPointsFileName); return null; }
public static ModelParent getModel(TrainPointsList list) { throw new NotImplementedException(); }
public static new LeastSquaresModel getModel(TrainPointsList trainPoints) { { var ReAn = trainPoints.Points.Select(x => x.ToList()); var Request = ReAn.Select(x => x.GetRange(0, x.Count - 1)).ToList(); var Answer = ReAn.Select(x => x.Last()).ToList(); MetrMath.Model.Build(Request, Answer); return new LeastSquaresModel(MetrMath.Model.model); } }
//TODO: Serialization/Deserialization from toTrainPoints have to move to MetrXML /// <summary> /// /// </summary> /// <param name="sourceFileName">Voted Metrics by experts</param> /// <param name="targetFileName">Points for train (already calculated metrics as coefficients)</param> public static void toTrainPoints(string sourceFileName, string targetFileName, Form LearnForm, ProgressBar progressBar) { Type[] estimationTypes = { typeof(EstimationOfElement) }; XmlSerializer serializer = new XmlSerializer(typeof(EstimationList), estimationTypes); var fs = new FileStream(sourceFileName, FileMode.Open); try { var votesList = (EstimationList)serializer.Deserialize(fs); Solution solution = null; Compilation compilation = null; string solutionPath = null; string projectToPick = null; //var coefs = new List<List<Int32>>(); var coefs = new TrainPointsList(); var ress = new List<Int32>(); int ttt = Environment.TickCount; LearnForm.Invoke(new Action( () => { progressBar.Maximum = votesList.Estimations.Count; progressBar.Minimum = 0; progressBar.Value = 0; } )); int k = 0; foreach (var v in votesList.Estimations) { int tt = Environment.TickCount; if (v.Solution != solutionPath || v.Project != projectToPick) Metr.RoslynAPI.ProjectCompile((solutionPath = v.Solution), (projectToPick = v.Project), out solution, out compilation); var curClass = compilation.GetTypeByMetadataName(v.FullName); int tt2 = Environment.TickCount - tt; LearnForm.Invoke(new Action( () => { progressBar.Value = k++; } )); if (curClass != null) coefs.AddPoint( // new TrainPoint(new List<Int32>() //{ // Metr.MetricCalculator.RS(compilation,curClass), // Metr.MetricCalculator.DIT(compilation,curClass), // Metr.MetricCalculator.NOC(solution,compilation,curClass), // Metr.MetricCalculator.CBO(solution, compilation,curClass), // v.Estimation //}, //v.FullName) TrainPoint.getClassRequestAnswerPoint(solution, compilation, v.FullName, v.Estimation) ); //ress.Add(v.Estimation); } int ttt2 = Environment.TickCount - ttt; coefs.SerializeTo(targetFileName); //Type[] estimationTypes2 = { typeof(TrainPoint) }; //XmlSerializer serializer2 = new XmlSerializer(typeof(TrainPointsList), estimationTypes2); //FileStream fs2 = new FileStream(targetFileName, FileMode.Create); //serializer2.Serialize(fs2, coefs); //fs.Close(); //Build(coefs, ress); //save to new file } finally { fs.Close(); } }