Ejemplo n.º 1
0
        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);
Ejemplo n.º 2
0
        public string MakeSummary(FuzzyModel data)
        {
            CalculateSets(data);
            var T = DegreeOfTruth(data);

            return(CreateLingusiticSummary(T, data));
        }
Ejemplo n.º 3
0
        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]));
                }
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        private async Task OnDuplicateModel(MouseEventArgs e, FuzzyModel fmodel)
        {
            FuzzyModel fm = fmodel.Clone();

            //fm.Name += " (kopia)";
            //fm.Description += " (kopia)";
            BoardProvider.Board.AddModel(fm);
        }
Ejemplo n.º 7
0
 private double LengthOfQualifier(FuzzyModel data)
 {
     if (qualifierNumber > 0)
     {
         return(2 * Math.Pow(0.5, qualifierSet.Length));
     }
     return(0);
 }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
        private double DegreeOfQuantifierImprecision(FuzzyModel data)
        {
            double value = quantifierParam.var.IntegrateSupp(quantifierParam.label);

            if (!quantifierParam.var.IsRelative())
            {
                value /= data.Length();
            }
            return(1 - value);
        }
Ejemplo n.º 10
0
        private double DegreeOfQuantifierCardinality(FuzzyModel data)
        {
            double value = quantifierParam.var.Integrate(quantifierParam.label);

            if (!quantifierParam.var.IsRelative())
            {
                value /= data.Length();
            }
            return(1 - value);
        }
Ejemplo n.º 11
0
 private ParametersModel()
 {
     PidLeft      = new PidModel();
     PidRight     = new PidModel();
     FuzzyLeft    = new FuzzyModel();
     FuzzyRight   = new FuzzyModel();
     EncoderLeft  = new EncoderModel();
     EncoderRight = new EncoderModel();
     Alarms       = new AlarmModel();
 }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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));
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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]));
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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();
            }
        }
Ejemplo n.º 21
0
 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);
     }
 }
Ejemplo n.º 22
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);
     }
 }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        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);
            }
        }
Ejemplo n.º 25
0
        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;
            }
        }
Ejemplo n.º 26
0
        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);
            }
        }
Ejemplo n.º 27
0
        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);
        }
Ejemplo n.º 28
0
 private double LengthOfSummary(FuzzyModel data)
 {
     return(2 * Math.Pow(0.5, summarizerSet.Length));
 }
Ejemplo n.º 29
0
 public override FuzzySet CreateSet(string label, FuzzyModel data)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 30
0
 protected override void OnInitialized()
 {
     this.selected_model = BoardProvider.Board.SelectedModel;
 }