public static Expression <Func <TEntity, bool> > GetFuzzyExpression(FuzzyModel model) { var func = FuzzyQueryHandlerMapping[model.FuzzyField]; if (func != default) { return(func(model)); } else if (PropertiesCache <TEntity> .PropMembers.Contains(model.FuzzyField) && !PropertiesCache <TEntity> .GetBlockWhereFields().Contains(model.FuzzyField)) { var action = NDelegate .DefaultDomain() .Func <FuzzyModel, Expression <Func <TEntity, bool> > >($@" Expression<Func<{typeof(TEntity).GetDevelopName()},bool>> exp = default; if(arg.IgnoreCase) {{ exp = obj => obj.{model.FuzzyField}.Contains(arg.FuzzyValue,StringComparison.CurrentCultureIgnoreCase); }} else {{ exp = obj => obj.{model.FuzzyField}.Contains(arg.FuzzyValue); }} return exp; "); _dict[model.FuzzyField] = action; FuzzyQueryHandlerMapping = _dict.PrecisioTree(); return(action(model)); } return(default);
public string MakeSummary(FuzzyModel data) { CalculateSets(data); var T = DegreeOfTruth(data); return(CreateLingusiticSummary(T, data)); }
public static void init(string path) { xmlReader = new XmlReader(path); connectionString = xmlReader.getConnectionString(); var db = new FuzzySql(connectionString); var tableName = xmlReader.GetTableName(); var dbAttributes = xmlReader.GetDBAttributes(); data = db.GetData(tableName, dbAttributes); hedges = xmlReader.GetHedges(); var linguisticParameters = xmlReader.GetLinguisticVariables(); for (int i = 0; i < linguisticParameters.Count; i++) { var type = linguisticParameters[i].type; if (type == LinguisticType.QuantifierRelative || type == LinguisticType.QuantifierAbsolute) { quantifiers.Add(new Quantifier(linguisticParameters[i])); } else if (type == LinguisticType.Qualifier) { qualifiers.Add(new Qualifier(linguisticParameters[i])); } else if (type == LinguisticType.Summarizer) { summarizers.Add(new Summarizer(linguisticParameters[i])); } } }
private string CreateLingusiticSummary(double degreeOfTruth, FuzzyModel data) { string q = quantifierParam.var.GetDisplayNames(quantifierParam.label) + " " + data.GetName() + " "; string w = ""; string s = "have "; if (qualifierNumber > 0) { w = "having "; foreach (var ww in qualifierParam) { w = w + ww.var.GetDisplayNames(ww.label); w = w + " "; w = w + ww.connector; w = w + " "; } } foreach (var ss in summarizerParam) { s = s + ss.var.GetDisplayNames(ss.label); s = s + " "; s = s + ss.connector; s = s + " "; } var summary = q + w + s + " [" + Math.Round(degreeOfTruth, 2).ToString() + "]"; return(summary); }
private double DegreeOfTruth(FuzzyModel data) { // calculate degree of thruth double m = -1; if (qualifierNumber > 0) { m = combineQualifierSet.Sum(); } else { if (quantifierParam.var.IsRelative()) { m = data.Length(); } else { m = 1; } } double r = combineSet.Sum(); var T = ComputeQualifier(r / m); return(T); }
private async Task OnDuplicateModel(MouseEventArgs e, FuzzyModel fmodel) { FuzzyModel fm = fmodel.Clone(); //fm.Name += " (kopia)"; //fm.Description += " (kopia)"; BoardProvider.Board.AddModel(fm); }
private double LengthOfQualifier(FuzzyModel data) { if (qualifierNumber > 0) { return(2 * Math.Pow(0.5, qualifierSet.Length)); } return(0); }
private async Task OnRemoveModel(MouseEventArgs e, FuzzyModel fmodel) { if (!await MessageBox.OkCancel(this.Modal, "Pytanie", $"Czy chcesz usunąć wybrany <b>model</b>?<p class=\"font-weight-light bg-light rounded\">{fmodel}</p>")) { return; } BoardProvider.Board.RemoveModel(fmodel); this.selected_model = BoardProvider.Board.SelectedModel; }
private double DegreeOfQuantifierImprecision(FuzzyModel data) { double value = quantifierParam.var.IntegrateSupp(quantifierParam.label); if (!quantifierParam.var.IsRelative()) { value /= data.Length(); } return(1 - value); }
private double DegreeOfQuantifierCardinality(FuzzyModel data) { double value = quantifierParam.var.Integrate(quantifierParam.label); if (!quantifierParam.var.IsRelative()) { value /= data.Length(); } return(1 - value); }
private ParametersModel() { PidLeft = new PidModel(); PidRight = new PidModel(); FuzzyLeft = new FuzzyModel(); FuzzyRight = new FuzzyModel(); EncoderLeft = new EncoderModel(); EncoderRight = new EncoderModel(); Alarms = new AlarmModel(); }
public double CreateFinalQualityMeasure(int [] indexes, double[] weights, FuzzyModel data) { double result = 0; for (int i = 0; i < indexes.Length; i++) { result += CreateQualityMeasure(indexes[i], data) * weights[i]; } return(result); }
private async Task OnEditModelDescription(MouseEventArgs e, FuzzyModel fmodel) { var in_data = new FuzzyModelDescriptionData(fmodel.Name, fmodel.Description); (bool result, FuzzyModelDescriptionData out_data) = await Modals.FuzzyEditors.FuzzyModelDescriptionEditor(this.Modal, in_data); if (result) { fmodel.Description = out_data.Description; fmodel.Name = out_data.Name; } }
private double DegreeOfSummarizerCardinality(FuzzyModel data) { double result = 1; foreach (var s in summarizerSet) { result *= ((double)s.SignmaCount() / data.Length()); } result = Math.Pow(result, 1 / summarizerSet.Length); return(result); }
public double CreateQualityMeasure(int number, FuzzyModel data) { double result = -1; switch (number) { case 0: result = DegreeOfTruth(data); break; case 1: result = DegreeOfImprecission(data); break; case 2: result = DegreeOfCovering(data); break; case 3: result = DegreeOfAppropiateness(data); break; case 4: result = LengthOfSummary(data); break; case 5: result = DegreeOfQuantifierImprecision(data); break; case 6: result = DegreeOfQuantifierCardinality(data); break; case 7: result = DegreeOfSummarizerCardinality(data); break; case 8: result = DegreeOfQualifierImprecision(data); break; case 9: result = DegreeOfQualifierCardinality(data); break; case 10: result = LengthOfQualifier(data); break; } return(Math.Round(result, 2)); }
private double DegreeOfImprecission(FuzzyModel data) { double result = 1; foreach (var s in summarizerSet) { double a = (double)s.Supp().Count / data.Length(); result *= a; } result = Math.Pow(result, 1 / summarizerSet.Length); return(result); }
private double DegreeOfAppropiateness(FuzzyModel data) { double result = 1; foreach (var s in summarizerSet) { result *= ((double)s.Supp().Count / (double)data.Length()); } result = result - DegreeOfCovering(data); result = Math.Abs(result); return(result); }
public override FuzzySet CreateSet(string label, FuzzyModel data) { int i = 0; for (i = 0; i < H.Length; i++) { if (H[i] == label) { break; } } return(new FuzzySet(data.Get("key").ToArray(), data.Get(attribute).ToArray(), G[i])); }
private double DegreeOfCovering(FuzzyModel data) { int h = data.Length(); if (qualifierNumber > 0) { h = combineQualifierSet.Supp().Count; } double t = (double)combineSet.Supp().Count; if (h == 0) { return(1); } return(t / h); }
private void InitializeModel() { using (StreamReader file = File.OpenText(@"config.json")) { JsonSerializer serializer = new JsonSerializer(); FuzzyConfig config = (FuzzyConfig)serializer.Deserialize(file, typeof(FuzzyConfig)); List <Chart> charts = new List <Chart>(); charts.Add(chart1); charts.Add(chart2); charts.Add(chart3); charts.Add(chart4); _fuzzyModel = new FuzzyModel(config, charts); _fuzzyModel.DrawCharts(); } }
private double DegreeOfQualifierCardinality(FuzzyModel data) { if (qualifierNumber > 0) { double result = 1; foreach (var w in qualifierSet) { result *= ((double)w.SignmaCount() / data.Length()); } result = Math.Pow(result, 1 / qualifierSet.Length); return(1 - result); } else { return(0); } }
private double DegreeOfQualifierImprecision(FuzzyModel data) { if (qualifierNumber > 0) { double result = 1; foreach (var w in qualifierSet) { result *= ((double)w.Supp().Count / data.Length()); } result = Math.Pow(result, 1 / qualifierSet.Length); return(1 - result); } else { return(1); } }
public static void NodeAggregation(FuzzyModel fm, float nodeCutoff) { BuildClusters(fm, nodeCutoff); Console.WriteLine("Edges remaining after building clusters:" + System.Environment.NewLine); foreach (FuzzyNode fn in fm.GetNodes()) { foreach (FuzzyEdge fe in fn.GetOutEdges()) { Console.WriteLine(fe.ToString()); } } // merge clusters MergeClusters(fm); // abstraction AbstractionClusters(fm); }
private void CreateFuzzySets(FuzzyModel data) { // calculate W fuzzy sets if (qualifierNumber > 0) { for (int i = 0; i < qualifierParam.Count; i++) { var variable = qualifierParam[i].var; qualifierSet[i] = variable.CreateSet(qualifierParam[i].label, data); } } // calculate S fuzzy set for (int i = 0; i < summarizerParam.Count; i++) { var variable = summarizerParam[i].var; summarizerSet[i] = variable.CreateSet(summarizerParam[i].label, data); } }
private void CalculateSets(FuzzyModel data) { CreateFuzzySets(data); if (qualifierNumber > 0) { qualifierSet = ModifySet(qualifierParam, qualifierSet); combineQualifierSet = CombineSet(qualifierParam, qualifierSet); } summarizerSet = ModifySet(summarizerParam, summarizerSet); combineSummarizerSet = CombineSet(summarizerParam, summarizerSet); if (qualifierNumber > 0) { combineSet = combineSummarizerSet.Intersection(combineQualifierSet); } else { combineSet = combineSummarizerSet; } }
private static void AbstractionClusters(FuzzyModel fm) { List <FuzzyNodeCluster> clustersToRemove = new List <FuzzyNodeCluster>(); List <FuzzyEdge> edgesToRemove = new List <FuzzyEdge>(); foreach (FuzzyNodeCluster fnc in fm.GetClusters()) { if (fnc.GetInEdges().Count == 0 && fnc.GetOutEdges().Count == 0) { clustersToRemove.Add(fnc); } else if (fnc.GetNodesInCluster().Count == 1) { foreach (FuzzyEdge fei in fnc.GetInEdges()) { foreach (FuzzyEdge feo in fnc.GetOutEdges()) { FuzzyEdge newFe = new FuzzyEdge(fei.GetFromNode(), feo.GetToNode()); if (!fm.GetEdges().Contains(newFe)) { fm.AddEdge(newFe); } } edgesToRemove.Add(fei); } clustersToRemove.Add(fnc); } } foreach (FuzzyNodeCluster fnc in clustersToRemove) { fm.RemoveCluster(fnc); } foreach (FuzzyEdge fe in edgesToRemove) { fm.RemoveEdge(fe); } }
public static FuzzyModel parseLogFile(string file) { FuzzyModel fm = new FuzzyModel(); List <XTrace> traces = getTracesXES(file); string root = "start_node"; string end = "end_node"; fm.AddNode(root); foreach (XTrace xt in traces) { fm.GetNode(root).IncreaseFrequencySignificance(); var xamTrace = xt.GetAttributes(); foreach (string key in xamTrace.Keys) { if (key != "concept:name") { fm.GetNode(root).AddSignificantAttribute(key, xamTrace[key].ToString()); } } string previousEvent = root; string previousState = ""; double eventDuration = 0; double traceDuration = 0; double previousTime = 0; foreach (XEvent xe in xt) { // find event name XAttributeMap xam = (XAttributeMap)xe.GetAttributes(); string currentEvent; string currentState = ""; if (xam.Keys.Contains <string>("lifecycle:transition")) { currentState = xam["lifecycle:transition"].ToString(); } double currentTime = 0; if (xam.Keys.Contains <string>("time:timestamp")) { currentTime = Convert.ToDateTime(xam["time:timestamp"].ToString()).ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; } currentEvent = xam["concept:name"].ToString(); // if the event is new, add it to the graph if (!fm.GetEvents().Contains(currentEvent)) { FuzzyNode node = new FuzzyNode(currentEvent); fm.AddNode(node); // if it is not the first event in the trace, add edges if (previousEvent != null) { FuzzyEdge e = new FuzzyEdge(fm.GetNode(previousEvent), node); // if the edge is new add it to the list if (!fm.GetNode(previousEvent).GetOutEdges().Contains(e)) { fm.AddEdge(e); } // if it's not the start node, compute the duration of the transition if (previousEvent != "start_node") { fm.GetEdge(e).AddDuration(currentTime - previousTime); traceDuration += currentTime - previousTime; } fm.GetEdge(e).IncreaseFrequencySignificance(); } fm.GetNode(currentEvent).IncreaseFrequencySignificance(); } else { // if it is not the first event in the trace, add edges if (previousEvent != null) { FuzzyEdge e = new FuzzyEdge(fm.GetNode(previousEvent), fm.GetNode(currentEvent)); // if the edge is new add it to the list if (!fm.GetNode(previousEvent).GetOutEdges().Contains(e)) { fm.AddEdge(e); } // if it's not the start node, compute the duration of the transition if (previousEvent != "start_node") { fm.GetEdge(e).AddDuration(currentTime - previousTime); traceDuration += currentTime - previousTime; } fm.GetEdge(e).IncreaseFrequencySignificance(); } // if the event is the same but the state is different, compute the event duration if (previousEvent == currentEvent && previousState != currentState) { if (previousState == "complete" && currentState == "start") { fm.GetNode(currentEvent).IncreaseFrequencySignificance(); } eventDuration += currentTime - previousTime; } else { fm.GetNode(currentEvent).IncreaseFrequencySignificance(); } } // if the event is complete add its duration to the node if (currentState == "complete") { fm.GetNode(currentEvent).AddDuration(eventDuration); traceDuration += eventDuration; eventDuration = 0; } // add the event attributes to the node foreach (string key in xam.Keys) { if (key != "concept:name" && key != "lifecycle:transition") { if (key != "time:timestamp" && key.IndexOf("id", StringComparison.OrdinalIgnoreCase) < 0) { fm.GetNode(currentEvent).AddSignificantAttribute(key, xam[key].ToString()); } fm.GetNode(currentEvent).AddAttribute(key, xam[key].ToString()); } } previousEvent = currentEvent; previousState = currentState; previousTime = currentTime; } if (!fm.GetEvents().Contains(end)) { fm.AddNode(end); fm.GetNode(end).IncreaseFrequencySignificance(); } else { fm.GetNode(end).IncreaseFrequencySignificance(); } FuzzyEdge fe = new FuzzyEdge(fm.GetNode(previousEvent), fm.GetNode(end)); if (!fm.GetEdges().Contains(fe)) { fm.AddEdge(fe); fm.GetEdge(fe).IncreaseFrequencySignificance(); } else { fm.GetEdge(fe).IncreaseFrequencySignificance(); } fm.GetNode(root).AddDuration(traceDuration); } foreach (XTrace xt in traces) { foreach (FuzzyNode fn in fm.GetNodes()) { foreach (XEvent xe in xt) { if (xe.GetAttributes()["concept:name"].ToString().Equals(fn.GetLabel())) { fn.IncreaseCaseFrequencySignificance(); break; } } } foreach (FuzzyEdge fe in fm.GetEdges()) { string previousEvent = ""; foreach (XEvent xe in xt) { string currentEvent = xe.GetAttributes()["concept:name"].ToString(); if (previousEvent.Equals(fe.GetFromNode().GetLabel()) && currentEvent.Equals(fe.GetToNode().GetLabel())) { fe.IncreaseCaseFrequencySignificance(); break; } previousEvent = currentEvent; } } } return(fm); }
private double LengthOfSummary(FuzzyModel data) { return(2 * Math.Pow(0.5, summarizerSet.Length)); }
public override FuzzySet CreateSet(string label, FuzzyModel data) { throw new NotImplementedException(); }
protected override void OnInitialized() { this.selected_model = BoardProvider.Board.SelectedModel; }