public static List<Segment> GetAllSegment() { List<Segment> result = new List<Segment>(); foreach(Time time in Time.GetAll()) foreach(Budget budget in Budget.GetAllData()) foreach(Companion companion in Companion.GetAllData()) //foreach(Familiarity familiarity in Familiarity.GetAllData()) //foreach(Mood mood in Mood.GetAllData()) //foreach(Temperature temperature in Temperature.GetAllData()) //foreach(TravelLength travelLength in TravelLength.GetAllData()) foreach(Weather weather in Weather.GetAllData()) { if (time.period_of_day == Time.Period_Of_Day.All && time.period_of_week == Time.Period_Of_Week.All && time.season == Time.Season.All && budget.id == 0 && companion.id == 0 && weather.id == 0) continue; else { Segment segment = new Segment(); segment.time = time; segment.budget = budget; segment.companion = companion; //segment.familiarity = familiarity; //segment.mood = mood; //segment.temperature = temperature; //segment.travelLength = travelLength; segment.weather = weather; segment.GetData(); if (segment.data.CountCells() > 100) result.Add(segment); } } return result; }
public static bool GetStrongSegments() { //List<Segment> AllSegment = Segment.GetAllSegment(); Segment root = Segment.GetRoot(); double sum_Correlation_Avg_root = 0; int count_Correlation_Avg_root = 0; DbHelper.RunScripts("truncate table segments", "Data Warehouse"); //foreach (Segment segment in AllSegment) //{ foreach(Time time in Time.GetAll()) foreach(Budget budget in Budget.GetAllData()) foreach(Companion companion in Companion.GetAllData()) foreach (Weather weather in Weather.GetAllData()) { if (time.period_of_day == Time.Period_Of_Day.All && time.period_of_week == Time.Period_Of_Week.All && time.season == Time.Season.All && budget.id == 0 && companion.id == 0 && weather.id == 0) continue; else { Segment segment = new Segment(); segment.time = time; segment.budget = budget; segment.companion = companion; //segment.familiarity = familiarity; //segment.mood = mood; //segment.temperature = temperature; //segment.travelLength = travelLength; segment.weather = weather; segment.GetData(); if (segment.data.CountCells() < 10) continue; //result.Add(segment); //Resample segment double performamce_segment = 0; double performance_root = 0; double correlation_avg_segment = 0; List<Sample> resamples = Sample.Resampling(segment); foreach (Sample sample in resamples) { double temp_corr_avg_segment = sample.Train(); if (!Double.IsNaN(temp_corr_avg_segment)) { correlation_avg_segment += temp_corr_avg_segment; performamce_segment += sample.Test(temp_corr_avg_segment); } Sample sample_root = new Sample(sample.Evaluation, sample.Training_root); double temp_corr_root = sample_root.Train(); if (!Double.IsNaN(temp_corr_root)) { sum_Correlation_Avg_root += temp_corr_root; count_Correlation_Avg_root += 1; performance_root += sample_root.Test(sum_Correlation_Avg_root / count_Correlation_Avg_root); } } //if (performamce_segment < performance_root) //if (!Double.IsNaN(performamce_segment) && !Double.IsNaN(correlation_avg_segment)) if (Double.IsNaN(performamce_segment)) performamce_segment = -9999; if (Double.IsNaN(correlation_avg_segment)) correlation_avg_segment = -9999; if (Double.IsNaN(performance_root)) performance_root = -9999; try { DbHelper.RunScripts(string.Format("pr_insertSegment " + "'" + segment.time.period_of_day.ToString() + "'" + ", '" + segment.time.period_of_week.ToString() + "'" + ", '" + segment.time.season.ToString() + "'" + ", " + segment.budget.id + ", " + segment.companion.id + ", " + segment.weather.id + ", " + performamce_segment / 10 + ", " + correlation_avg_segment / 10 + ", " + performance_root / 10 + ", " + sum_Correlation_Avg_root / count_Correlation_Avg_root) , "Data Warehouse"); } catch (Exception ex) { } } //Remove segment "child" and have performance less than its parents /* Segment[] candidates = Segment.GetCandidates(); for (int i = 0; i < candidates.Length - 1; i++) { for (int j = i + 1; j < candidates.Length; j++) { if (candidates[j].IsChildOf(candidates[i])) { DbHelper.RunScripts(string.Format("delete from segments where id = " + candidates[j].id), "Data Warehouse"); } } }*/ } DbHelper.RunScripts(string.Format("pr_insertSegment " + "'All', 'All', 'All'" + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 9999 + ", " + sum_Correlation_Avg_root / count_Correlation_Avg_root), "Data Warehouse"); return true; }