static void Main(string[] args) { // Initialize the case base org.opencbr.core.engine.DefaultEngine _engine = new org.opencbr.core.engine.DefaultEngine(); string _env = @"D:\projects\opencbr\sample\workspace\config.xml"; _engine.SetEnvironmentVariable(_env); // Initialize the problem Case _problem = new Case(1, "cooling", "cooling problem"); _problem.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 19.0, 0.3, false, false); _problem.AddFeature("temp", FeatureType.TYPE_FEATURE_FLOAT, 44.0, 0.7, false, false); ////initialize to 51 or 44 to demo retrieval of closest cases (3 versus 4) from Database _problem.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 232.0, 1.0, false, false); _engine.SetProblem(_problem); // Run the reasoning engine _engine.Startup(); _engine.Run(); // Print the result of reasoning org.opencbr.core.context.ICBRContext ctx = _engine.GetCBRContext(); org.opencbr.core.express.Case c = ctx.GetSolutionCase(); Console.WriteLine(c); }
[SetUp] public void Init() { //_problem.AddFeature("硬度等级", FeatureType.TYPE_FEATURE_INT, // 193, 1, false, false); //_problem.AddFeature("厚度等级", FeatureType.TYPE_FEATURE_INT, // 2, 1, false, false); //_problem.AddFeature("目标卷温等级", FeatureType.TYPE_FEATURE_INT, // 1, 1, false, false); //_problem.AddFeature("目标卷温", FeatureType.TYPE_FEATURE_FLOAT, // 570.056, 1, false, false); //_problem.AddFeature("终轧厚度", FeatureType.TYPE_FEATURE_FLOAT, // 2.6, 1, false, false); //_problem.AddFeature("终轧速度", FeatureType.TYPE_FEATURE_FLOAT, // 11.12, 1, false, false); //_problem.AddFeature("水温", FeatureType.TYPE_FEATURE_FLOAT, // 31.35, 1, false, false); //_problem.AddFeature("上始阀", FeatureType.TYPE_FEATURE_INT, // 45, 1, true, true); _problem.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 19.0, 0.3, false, false); _problem.AddFeature("temp", FeatureType.TYPE_FEATURE_FLOAT, 44.0, 0.7, false, false); ////initialize to 51 or 44 to demo retrieval of closest cases (3 versus 4) from Database _problem.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 232.0, 1.0, false, false); _engine.SetEnvironmentVariable(_env); _engine.SetProblem(_problem); }
public static Case Clone(Case c) { if (c == null) { return(null); } FeatureList list = new FeatureList(); Case instance = CaseFactory.CreateInstance(c.GetCaseID(), c.GetCaseName(), c.GetCaseDescription(), c.GetCaseType(), list); System.Collections.ArrayList features = c.GetFeatures(); foreach (Feature f in features) { c.AddFeature(f.GetFeatureName(), f.GetFeatureType(), f.GetFeatureValue(), f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } return(instance); }
/// <summary> /// test init /// case 1 data: /// speed 2.0 /// temperature 3.5 /// quality 0.7 /// result 1 /// case 2 data: /// speed 3.0 /// temperature 6.7 /// quality 0.6 /// result 2 /// /// </summary> [SetUp] public void Init() { c1.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 2.0, 0.5, false, false); c2.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 3.0, 0.5, false, false); c1.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT, 3.0, 0.3, false, false); c2.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT, 4.0, 0.3, false, false); c1.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 1.0, 0.2, false, false); c2.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 2.0, 0.2, false, false); c1.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT, 1.0, 0, true, false); c2.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT, 2.0, 0, true, false); }
private void CreateCase(string[] values) { Case c = CaseFactory.CreateInstance(_caseName); c.SetCaseID(_caseID); for (int i = 0; i < _featureNames.Length; i++) { string name = _featureNames[i]; string v = values[i]; Feature f = Find(name); if (f != null) { if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) { } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_FLOAT) { double fValue = Convert.ToDouble(v); c.AddFeature(f.GetFeatureName(), f.GetFeatureType(), fValue, f.GetWeight(), f.GetIsKey(), f.GetIsIndex()); } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_IMAGE) { } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT) { } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_MSTRING) { } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_STRING) { } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_UNDEFINED) { } } } _cases.Add(c); _caseID++; }
/// <summary> /// Find the mean point of the given point cloud /// </summary> /// <param name="points">A set of points</param> /// <returns>The centroid</returns> private static Case mean(IEnumerable <Case> points) { int count = points.Count(); int sumf = 0; Feature f = new Feature(); Case result = new Case(1, "", ""); for (int j = 1; j < points.First().GetFeatures().Count; j++) { Feature r = (Feature)result.GetFeatures()[j]; foreach (Case c in points) { f = (Feature)c.GetFeatures()[j]; if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT) { sumf += (int)f.GetFeatureValue(); } } result.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumf / points.Count(), 1.0, false, false, f.GetFeatureUnit()); } return(result); }
public static Case ReCalcCentroid(List <Case> list, int centroid_id) // generate new centroid for the cluster { int count = list.Count(); List <int> sums_count = new List <int>(); Case result = null; int sumf = 0; double sumd = 0; bool sumb = false; List <string> sumst = new List <string>(); if (count != 0) { Feature f = new Feature(); result = new Case(list[0].GetCaseID(), list[0].GetCaseName(), list[0].GetCaseDescription()); for (int j = 0; j < list.First().GetFeatures().Count; j++) { foreach (Case c in list) { f = (Feature)c.GetFeatures()[j]; if (f.GetFeatureName() == "id" || f.GetFeatureName() == "cluster") { break; } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT) { sumf += Convert.ToInt32(f.GetFeatureValue()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_FLOAT) { sumd += Convert.ToDouble(f.GetFeatureValue()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) { sumb = (sumb || Convert.ToBoolean(f.GetFeatureValue())); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_STRING || f.GetFeatureType() == FeatureType.TYPE_FEATURE_CATEGORICAL) { int position = sumst.IndexOf(f.GetFeatureValue().ToString()); if (position >= 0) { sums_count[position] = sums_count[position] + 1; } else { sumst.Add(f.GetFeatureValue().ToString()); sums_count.Add(1); } } } if (f.GetFeatureName() == "cluster") { result.AddFeature(f.GetFeatureName(), f.GetFeatureType(), -1, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureName() == "id") { result.AddFeature(f.GetFeatureName(), f.GetFeatureType(), centroid_id, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT) { result.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumf / list.Count(), f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_FLOAT) { result.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumd / list.Count(), f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) { result.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumb, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_STRING || f.GetFeatureType() == FeatureType.TYPE_FEATURE_CATEGORICAL) { int max = sums_count.IndexOf(sums_count.Max()); string string_value = sumst[max]; result.AddFeature(f.GetFeatureName(), f.GetFeatureType(), string_value, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); /* Random rd = new Random(); // for calculating random numbers * int rnd = rd.Next(sumst.Count); * result.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumst[rnd].ToString(), 1.0, false, false,"");*/ } sumf = 0; sumd = 0; sumb = false; } } return(result); }
/// <summary> /// Get the centroid of a set of points /// cf. http://en.wikipedia.org/wiki/Centroid /// Consider also: Metoid cf. http://en.wikipedia.org/wiki/Medoids /// </summary> /// <param name="pcs"></param> /// <returns></returns> private List <Case> GetCentroid(PointClusters pcs) { List <Case> newSeeds = new List <Case>(pcs.PC.Count); int sumf = 0; double sumd = 0; bool sumb = false; List <string> sumst = new List <string>(); List <int> sums_count = new List <int>(); Feature f = new Feature(); int t = 0; foreach (List <Case> cluster in pcs.PC.Values) { Case newSeed = new Case(cluster[0].GetCaseID(), cluster[0].GetCaseName(), cluster[0].GetCaseDescription()); for (int j = 0; j < cluster[0].GetFeatures().Count; j++) { foreach (Case p in cluster) { f = (Feature)p.GetFeatures()[j]; if (f.GetFeatureName() == "id" || f.GetFeatureName() == "cluster") { break; } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT || f.GetFeatureType() == FeatureType.TYPE_FEATURE_Ordinal) { sumf += Convert.ToInt32(f.GetFeatureValue()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_FLOAT) { sumd += Convert.ToDouble(f.GetFeatureValue()); } // else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) // sumb = (sumb || Convert.ToBoolean(f.GetFeatureValue())); else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_STRING || f.GetFeatureType() == FeatureType.TYPE_FEATURE_CATEGORICAL || f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) { int position = sumst.IndexOf(f.GetFeatureValue().ToString()); if (position >= 0) { sums_count[position] = sums_count[position] + 1; } else { sumst.Add(f.GetFeatureValue().ToString()); sums_count.Add(1); } } } if (f.GetFeatureName() == "cluster") { newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), -1, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureName() == "id") { newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), t, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT || f.GetFeatureType() == FeatureType.TYPE_FEATURE_Ordinal) { newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumf / cluster.Count(), f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_FLOAT) { newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumd / cluster.Count(), f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) { int max = sums_count.IndexOf(sums_count.Max()); sumb = Convert.ToBoolean(sumst[max]); newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumb, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_STRING || f.GetFeatureType() == FeatureType.TYPE_FEATURE_CATEGORICAL) { int max = sums_count.IndexOf(sums_count.Max()); string string_value = sumst[max]; newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), string_value, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } sumf = 0; sumd = 0; sumb = false; sumst.Clear(); sums_count.Clear(); } // end feature newSeeds.Add(newSeed); sumf = 0; sumd = 0; sumb = false; sumst.Clear(); sums_count.Clear(); t++; }// end clusters return(newSeeds); }
//========================================================================================= public void GenerateRandomCases() { exp_random_cases.Clear(); Case Max_Mean = Db.get_Case_data(standrize_table, -2); Case Min_Sd = Db.get_Case_data(standrize_table, -3); Random r = new Random(); List <Case> Cases = Db.get_cases_condition(tablename, casename); for (int i = 0; i < 100; i++) { double x = 0; Case c = new Case(0, Max_Mean.GetCaseName(), ""); for (int j = 0; j < Max_Mean.GetFeatures().Count; j++) { Feature max_f = (Feature)Max_Mean.GetFeatures()[j]; Feature min_f = (Feature)Min_Sd.GetFeatures()[j]; if (max_f.GetFeatureName() == "id") { x = (double)i; } else if (max_f.GetFeatureName() == "cluster") { x = -1; } else if (max_f.GetFeatureType() >= 5 && max_f.GetFeatureType() <= 9)// mstring, string, ordinal, categorical { int k = r.Next(0, Cases.Count); Feature f = (Feature)Cases[k].GetFeatures()[j]; c.AddFeature(max_f.GetFeatureName(), max_f.GetFeatureType(), f.GetFeatureValue(), max_f.GetWeight(), max_f.GetIsKey(), max_f.GetIsIndex(), max_f.GetFeatureUnit()); continue; } else if (max_f.GetFeatureType() == 1)// mstring, string, ordinal, categorical { int k = r.Next(0, 2); bool o = false; if (k == 1) { o = true; } c.AddFeature(max_f.GetFeatureName(), max_f.GetFeatureType(), o, max_f.GetWeight(), max_f.GetIsKey(), max_f.GetIsIndex(), max_f.GetFeatureUnit()); continue; } else if (max_f.GetFeatureType() == 2) { int max = Convert.ToInt32(max_f.GetFeatureValue()); int min = Convert.ToInt32(min_f.GetFeatureValue()); x = r.Next(min, max + 1); } else { double max = Convert.ToDouble(max_f.GetFeatureValue()); double min = Convert.ToDouble(min_f.GetFeatureValue()); x = r.NextDouble(min, max + 0.05); x = Math.Round(x, 1); } c.AddFeature(max_f.GetFeatureName(), max_f.GetFeatureType(), x, max_f.GetWeight(), max_f.GetIsKey(), max_f.GetIsIndex(), max_f.GetFeatureUnit()); } exp_random_cases_nonstandrize.Add(c); // i have to put general seetings for normalization exp_random_cases.Add(BestChoice.StandardizeCase(c, Max_Mean, Min_Sd, standrize_type)); } }
public static ArrayList GetCases(DataSource ds, string dictionaryTable, string dataTable, string caseID) { string sql = "select * from " + dictionaryTable + " where "+ FIELD_CASEID + "='" + caseID + "'"; try { //read case structure Case c = CaseFactory.CreateInstance(caseID); OleDbConnection conn = new OleDbConnection(ds.GetConnectionString()); OleDbCommand cmd = conn.CreateCommand(); conn.Open(); OleDbDataReader reader = ExecuteQuery(cmd, sql); while (reader.Read()) { string name = reader[FIELD_FEATURENAME].ToString(); string type = reader[FIELD_FEATURETYPE].ToString(); string key = reader[FIELD_KEY].ToString(); string index = reader[FIELD_INDEX].ToString(); string weight = reader[FIELD_WEIGHT].ToString(); string unit = reader[FIELD_FEATUREUNIT].ToString(); c.AddFeature(name, GetType(type), null, Convert.ToDouble(weight), GetBOOL(key), GetBOOL(index), unit); } reader.Close(); //read cases ArrayList features = c.GetFeatures(); ArrayList cases = new ArrayList(); if (ds.GetConditions() != null) { sql = "select * from " + dataTable + " where " + FIELD_CASEID + "='" + caseID + "' and " + ds.GetConditions(); } else { sql = "select * from " + dataTable + " where " + FIELD_CASEID + "='" + caseID + "'"; } reader = ExecuteQuery(cmd, sql); while (reader.Read()) { Case theCase = CaseFactory.CreateInstance(caseID); foreach (Feature f in features) { string featureName = f.GetFeatureName(); object featureValue = reader[featureName]; theCase.AddFeature(f.GetFeatureName(), f.GetFeatureType(), featureValue, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } cases.Add(theCase); } reader.Close(); cmd.Cancel(); conn.Close(); return(cases); } catch (Exception e) { System.Console.WriteLine(e.Message); return(null); } }
private void button5_Click_1(object sender, EventArgs e) { statistics = new Statistics(mybestchoice.TableName, mybestchoice.CaseName); Case Max_Mean = Db.get_Case_data(statistics.standrize_table, -2); Case Min_Sd = Db.get_Case_data(statistics.standrize_table, -3); string url = ""; System.IO.StreamReader reader = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); ArrayList inputs = new ArrayList(); // Set filter options and filter index. openFileDialog1.Filter = "Text Files (.key)|*.key|All Files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.Multiselect = true; // Call the ShowDialog method to show the dialog box. DialogResult userClickedOK = openFileDialog1.ShowDialog(); // Process input if the user clicked OK. if (userClickedOK.Equals(DialogResult.OK)) { url = openFileDialog1.FileName; reader = File.OpenText(url); if (reader == null) { System.Console.WriteLine("file open failed " + url); return; } for (int i = 0; i < dataGV_CaseEntries.Rows.Count; i++) { string s = reader.ReadLine(); dataGV_CaseEntries.Rows[i].Cells["UserEntry"].Value = s; inputs.Add(s); } reader.Close(); } Case _problem = new Case(0, mybestchoice.CaseName, ""); _problem.AddFeature("id", FeatureType.TYPE_FEATURE_INT, 0, 1.0, false, false, "num"); for (int i = 0; i < dataGV_CaseEntries.Rows.Count - 1; i++) { if (dataGV_CaseEntries.Rows[i].Cells["UserEntry"].Value.ToString() != "".ToString()) { _problem.AddFeature( dataGV_CaseEntries.Rows[i].Cells["FeatureName"].Value.ToString().Trim(), Token.GetType(dataGV_CaseEntries.Rows[i].Cells["FeatureType"].Value.ToString().Trim()), dataGV_CaseEntries.Rows[i].Cells["UserEntry"].Value.ToString().Trim(), Convert.ToDouble(dataGV_CaseEntries.Rows[i].Cells["FeatureWeight"].Value.ToString().Trim()), Convert.ToBoolean(dataGV_CaseEntries.Rows[i].Cells["FeatureKey"].Value.ToString().Trim()), Convert.ToBoolean(dataGV_CaseEntries.Rows[i].Cells["FeatureIndex"].Value.ToString().Trim()), dataGV_CaseEntries.Rows[i].Cells["FeatureUnit"].Value.ToString().Trim()); } } _problem.AddFeature("cluster", FeatureType.TYPE_FEATURE_INT, 0, 1.0, false, false, "num"); statistics.exp_random_cases.Add(BestChoice.StandardizeCase(_problem, Max_Mean, Min_Sd, statistics.standrize_type)); statistics.exp_random_cases_nonstandrize.Add(_problem); mybestchoice.Problem = statistics.exp_random_cases_nonstandrize[0]; mybestchoice.StandrizeProblem = statistics.exp_random_cases[0]; }
private void CreateCase(string[] values) { Case c = CaseFactory.CreateInstance(_caseName); c.SetCaseID(_caseID); if (_with_id) { c.AddFeature("id", FeatureType.TYPE_FEATURE_INT, feasture_id, 1.0, false, false, "num"); } feasture_id++; for (int i = 0; i < _featureNames.Length; i++) { string name = _featureNames[i]; string v = values[i]; Feature f = Find(name); if (f != null) { if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) { if (v == "1") { v = "True"; } else { v = "False"; } bool fValue = Convert.ToBoolean(v); c.AddFeature(f.GetFeatureName(), f.GetFeatureType(), fValue, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_FLOAT) { double fValue = Convert.ToDouble(v); c.AddFeature(f.GetFeatureName(), f.GetFeatureType(), fValue, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_IMAGE) { } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT) { int fValue = Convert.ToInt32(v); c.AddFeature(f.GetFeatureName(), f.GetFeatureType(), fValue, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_MSTRING) { } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_STRING) { string fValue = v; c.AddFeature(f.GetFeatureName(), f.GetFeatureType(), fValue, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_CATEGORICAL) { string fValue = v; c.AddFeature(f.GetFeatureName(), f.GetFeatureType(), fValue, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_Ordinal) { int fValue = Convert.ToInt32(v); c.AddFeature(f.GetFeatureName(), f.GetFeatureType(), fValue, f.GetWeight(), f.GetIsKey(), f.GetIsIndex(), f.GetFeatureUnit()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_UNDEFINED) { } } } if (_with_id) { c.AddFeature("cluster", FeatureType.TYPE_FEATURE_INT, -4, 1.0, false, false, "num"); } _cases.Add(c); _list_cases.Add(c); _caseID++; }
[SetUp] public void Init() { if (list.Count > 0) { list.Clear(); } c1.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 2.0, 0.5, false, false); c2.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 3.8, 0.5, false, false); c3.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 7.0, 0.5, false, false); c4.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 9.0, 0.5, false, false); c5.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT, 5.0, 0.5, false, false); c1.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT, 3.0, 0.3, false, false); c2.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT, 4.0, 0.3, false, false); c3.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT, 2.0, 0.3, false, false); c4.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT, 7.0, 0.3, false, false); c5.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT, 1.0, 0.3, false, false); c1.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 1.0, 0.2, false, false); c2.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 2.0, 0.2, false, false); c3.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 5.0, 0.2, false, false); c4.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 7.0, 0.2, false, false); c5.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT, 3.0, 0.2, false, false); c1.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT, 1.0, 0, true, false); c2.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT, 2.0, 0, true, false); c3.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT, 6.0, 0, true, false); c4.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT, 8.0, 0, true, false); c5.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT, 11.0, 0, true, false); IStat s1 = StatFactory.newInstance(); s1.SetCBRCase(c1); s1.SetCaseSimilarity(400.03); list.Add(s1); IStat s2 = StatFactory.newInstance(); s2.SetCBRCase(c2); s2.SetCaseSimilarity(300.3); list.Add(s2); IStat s3 = StatFactory.newInstance(); s3.SetCBRCase(c3); s3.SetCaseSimilarity(200.4); list.Add(s3); IStat s4 = StatFactory.newInstance(); s4.SetCBRCase(c4); s4.SetCaseSimilarity(100.45); list.Add(s4); IStat s5 = StatFactory.newInstance(); s5.SetCBRCase(c5); s5.SetCaseSimilarity(80.23); list.Add(s5); //test case 1 stat1 = StatFactory.newInstance(); stat1.SetCBRCase(c1); stat1.SetCaseSimilarity(111.098); //test case 2 for upper bound stat2 = StatFactory.newInstance(); stat2.SetCBRCase(c1); stat2.SetCaseSimilarity(50.098); //test case 3 for under bound stat3 = StatFactory.newInstance(); stat3.SetCBRCase(c1); stat3.SetCaseSimilarity(1110.098); }
/// <summary> /// Get the centroid of a set of points /// cf. http://en.wikipedia.org/wiki/Centroid /// Consider also: Metoid cf. http://en.wikipedia.org/wiki/Medoids /// </summary> /// <param name="pcs"></param> /// <returns></returns> private List <Case> GetCentroid(PointClusters pcs) { List <Case> newSeeds = new List <Case>(pcs.PC.Count); Case newSeed; int sumf = 0; double sumd = 0; bool sumb = false; List <string> sumst = new List <string>(); Feature f = new Feature(); foreach (List <Case> cluster in pcs.PC.Values) { newSeed = new Case(cluster[0].GetCaseID(), cluster[0].GetCaseName(), cluster[0].GetCaseDescription()); for (int j = 0; j < cluster[0].GetFeatures().Count; j++) { foreach (Case p in cluster) { f = (Feature)p.GetFeatures()[j]; if (f.GetFeatureName() == "id") { break; } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT) { sumf += Convert.ToInt32(f.GetFeatureValue()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_FLOAT) { sumd += Convert.ToDouble(f.GetFeatureValue()); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) { sumb = (sumb || Convert.ToBoolean(f.GetFeatureValue())); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_STRING) { sumst.Add(f.GetFeatureValue().ToString()); } } if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_INT) { newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumf / cluster.Count(), 1.0, false, false, ""); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_FLOAT) { newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumd / cluster.Count(), 1.0, false, false, ""); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_BOOL) { newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumb, 1.0, false, false, ""); } else if (f.GetFeatureType() == FeatureType.TYPE_FEATURE_STRING) { Random rd = new Random(); // for calculating random numbers int rnd = rd.Next(sumst.Count); newSeed.AddFeature(f.GetFeatureName(), f.GetFeatureType(), sumst[rnd].ToString(), 1.0, false, false, ""); } // newSeed = new Case(sumX / cluster.Count, sumY / cluster.Count); // newSeeds.Add(newSeed); } newSeeds.Add(newSeed); sumf = 0; sumd = 0; sumb = false; sumst.Clear(); } return(newSeeds); }