Esempio n. 1
0
        public WordFrequencyRatingDataSource(FrequencyList frequencyList)
        {
            var words = frequencyList.GetAllWords().Materialize();
            var count = words.Count;

            frequencies = words.Select((kvp, i) => new KeyValuePair <string, double>(kvp.Key, (double)(count - i + 1) / (count + 1) * 10)).ToDictionary();
        }
Esempio n. 2
0
        public void ExecuteDeleteSelectedFrequencies(ICollection <object> selectedItems)
        {
            IList <object> copy = selectedItems.ToList <object>();

            foreach (var item in copy)
            {
                FrequencyList.Remove((double)item);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Generates a canonical depth-limited Huffman tree using the provided <paramref name="symbolFrequencies"/>.
 /// </summary>
 public static HuffmanTree <T> FromSymbols(FrequencyList <T> symbolFrequencies, byte maxDepth)
 {
     if (symbolFrequencies.Count == 0)
     {
         throw new ArgumentOutOfRangeException(nameof(symbolFrequencies), "Cannot generate a tree with no symbols.");
     }
     else if (symbolFrequencies.Count == 1)
     {
         return(new HuffmanTree <T>(new HuffmanNode <T> .Leaf(symbolFrequencies.First())));
     }
     else
     {
         return(new HuffmanTree <T>(HuffmanGenerator <T> .FromFrequenciesCanonical(symbolFrequencies.HuffmanFreq.ToArray(), maxDepth)));
     }
 }
Esempio n. 4
0
        static Constants()
        {
            //  APIID = DataAccess.Security;
            // DefaultAvatar = string.Format("data:image/png;base64,{0}", Convert.ToBase64String(Mirrovest.Shared.AvatarCreator.CreateAvatar(File.OpenRead(HttpContext.Current.Server.MapPath("~/Content/elements/bigavatar.png")))));
            EmailHost        = ConfigurationManager.AppSettings["EmailHost"];
            EmailUsername    = ConfigurationManager.AppSettings["EmailUsername"];
            EmailPassword    = ConfigurationManager.AppSettings["EmailPassword"];
            EmailFromAddress = ConfigurationManager.AppSettings["EmailFromAddress"];
            EmailFromName    = ConfigurationManager.AppSettings["EmailFromName"];
            DefaultLanguage  = ConfigurationManager.AppSettings["DefaultLanguage"];

            ScalesList = SADFM.Data.DataAccess.ListItem.GetList("Scale").ToList();
            //ImpairmentClassList = SADFM.Data.DataAccess.ListItem.GetList("ImpairmentClass").OrderBy(x => Convert.ToInt32(x.SortOrder)).SelectMany(li => li.Children.OrderBy(x => x.SortOrder)).ToList();
            ImpairmentClassList = SADFM.Data.DataAccess.ListItem.GetImpairmentClass();
            AdmissionStatusList = SADFM.Data.DataAccess.ListItem.GetImpairmentClass();
            FrequencyList       = SADFM.Data.DataAccess.ListItem.GetList("Frequency", deep: false).ToList();

            RolesList             = SADFM.Data.DataAccess.ListItem.GetList("Role");
            TitleComboBox         = SADFM.Web.Shared.HtmlHelper.DropdownBox(SADFM.Data.DataAccess.ListItem.GetList("Title", deep: false), "TitleID", l => l.ID, l => l.Name, "chosen-select", dataPlaceholder: "Select title");
            GenderComboBox        = SADFM.Web.Shared.HtmlHelper.DropdownBox(SADFM.Data.DataAccess.ListItem.GetList("Gender", deep: false), "GenderID", l => l.ID, l => l.Name, "chosen-select", dataPlaceholder: "Gender");
            RaceComboBox          = SADFM.Web.Shared.HtmlHelper.DropdownBox(SADFM.Data.DataAccess.ListItem.GetList("Race", deep: false), "RaceID", l => l.ID, l => l.Name, "chosen-select", dataPlaceholder: "Race");
            MedicalSchemeComboBox = SADFM.Web.Shared.HtmlHelper.DropdownBox(SADFM.Data.DataAccess.ListItem.GetList("MedicalScheme", deep: false).OrderByDescending(x => x.SortOrder).ThenBy(x => x.Description).ToList(), "medicalscheme", l => l.ID, l => l.Description, "chosen-select", dataPlaceholder: "Medical Scheme");

            var medicalShemeListMulti = SADFM.Data.DataAccess.ListItem.GetList("MedicalScheme", deep: false).OrderByDescending(x => x.SortOrder).ThenBy(x => x.Description).ToList();

            medicalShemeListMulti.Insert(0, new Data.Models.ListItem()
            {
                Description = "All", ID = "All"
            });
            MedicalSchemeComboBoxMulti = SADFM.Web.Shared.HtmlHelper.DropdownBox(medicalShemeListMulti, "MedicalSchemes", l => l.GUID.ToString(), l => l.Description, "chosen-select", dataPlaceholder: "Medical Schemes", multiple: true);

            CountryComboBox     = SADFM.Web.Shared.HtmlHelper.DropdownBox(SADFM.Data.DataAccess.ListItem.GetList("Country", deep: false), "CountryID", l => l.ID, l => l.Description, "chosen-select", dataPlaceholder: "Country");
            ScalesComboBox      = SADFM.Web.Shared.HtmlHelper.DropdownBox(ScalesList, "ScaleId", s => s.GUID.ToString(), s => s.Description, "chosen-select", dataPlaceholder: "Select scale");
            ScalesComboBoxMulti = SADFM.Web.Shared.HtmlHelper.DropdownBox(ScalesList, "Scales", s => s.GUID.ToString(), s => s.Description, "chosen-select", dataPlaceholder: "Select scale", multiple: true);

            FrequencyComboBox = SADFM.Web.Shared.HtmlHelper.DropdownBox(FrequencyList.OrderBy(x => x.SortOrder).ToList(), "FrequencyID", f => f.ID, f => f.Description, "chosen-select", dataPlaceholder: "Select frequency");
            DefaultCountryId  = SADFM.Data.Models.BaseModel.EncryptId(SADFM.Data.DataAccess.ListItem.GetListItemIdByName(ConfigurationManager.AppSettings["DefaultCountry"]));
#if (DEBUG)
            Debugging = true;
#else
            Debugging = false;
#endif
        }
            /// <summary>
            /// Adapted from https://github.com/google/brotli/blob/master/c/enc/bit_cost.h (BitsEntropy, ShannonEntropy)
            /// </summary>
            private static double BitsEntropy(FrequencyList <T> histogram)
            {
                int    total = 0;
                double calc  = 0.0;

                foreach (var symbol in histogram)
                {
                    var freq = histogram[symbol];

                    total += freq;
                    calc  -= freq * Math.Log(freq, 2.0);
                }

                if (total > 0)
                {
                    calc += total * Math.Log(total, 2.0);
                }

                return(Math.Max(calc, total));
            }
Esempio n. 6
0
 public void ExecuteReadConfig()
 {
     try
     {
         _cvConfiguration.LoadConfiguration(ConfigurationFile);
         StartVoltage     = _cvConfiguration.StartVoltage;
         FinalVoltage     = _cvConfiguration.FinalVoltage;
         IncrementVoltage = _cvConfiguration.IncrementVoltage;
         CurrentLimit     = _cvConfiguration.CurrentLimit;
         Amplitude        = _cvConfiguration.Amplitude;
         FrequencyList.Clear();
         foreach (var frequency in _cvConfiguration.TestWaveFrequency)
         {
             FrequencyList.Add(frequency);
         }
         StatusMessage = $"Configuration File {ConfigurationFile} loaded";
     }
     catch (Exception ex)
     {
         StatusMessage = $"Error {ex.Message} reading Configuration File: {ConfigurationFile}";
     }
 }
Esempio n. 7
0
            /// <summary>
            /// Adapted from https://github.com/google/brotli/blob/master/c/enc/compress_fragment.c (ShouldMergeBlock).
            /// </summary>
            private bool ShouldMergeBlock(int ip, int blockSize)
            {
                const int            sampleRate = 43;
                FrequencyList <byte> bytes      = new FrequencyList <byte>();

                for (int offset = 0; offset < blockSize; offset += sampleRate)
                {
                    bytes.Add(input[ip + offset]);
                }

                int    total = (blockSize + sampleRate - 1) / sampleRate;
                double r     = ((total == 0 ? 0 : Math.Log(total, 2.0) + 0.5) * total) + 200;

                foreach (var symbol in bytes)
                {
                    var samples = bytes[symbol];
                    var literal = new Literal(symbol);

                    r -= samples * (literalTree !.FindPath(literal).Length + Math.Log(samples, 2.0));
                }

                return(r >= 0.0);
            }
            public void ProcessSequence(BlockSwitchBuilder builder, List <T> sequence, ContextInfo?contextParam = null)
            {
                builder.Reset();

                ContextInfo ctx = contextParam ?? ContextInfo.Default;

                int numContexts   = 1 + ctx.Map.Max();
                int maxBlockTypes = 256 / numContexts;

                int maxNumBlocks = sequence.Count / minBlockSize + 1;
                var histograms   = FrequencyList <T> .Array(numContexts *Math.Min(maxNumBlocks, maxBlockTypes + 1));

                int numBlocks       = 0;
                int blockSize       = 0;
                int targetBlockSize = minBlockSize;
                int currHistogramIx = 0;
                var lastHistogramIx = new int[2];
                var lastEntropy     = new double[2 * numContexts];
                int mergeLastCount  = 0;

                void FinishBlock(bool isFinal)
                {
                    blockSize = Math.Max(blockSize, minBlockSize);

                    if (numBlocks == 0)
                    {
                        builder.SetInitialLength(blockSize);

                        for (int context = 0; context < numContexts; context++)
                        {
                            lastEntropy[context] = BitsEntropy(histograms[context]);
                            lastEntropy[context + numContexts] = lastEntropy[context];
                        }

                        currHistogramIx += numContexts;

                        ++numBlocks;
                        blockSize = 0;
                    }
                    else if (blockSize > 0)
                    {
                        var entropy       = new double[numContexts];
                        var combinedHisto = FrequencyList <T> .Array(2 *numContexts);

                        var combinedEntropy = new double[2 * numContexts];
                        var diff            = new double[2];

                        for (int context = 0; context < numContexts; context++)
                        {
                            int currHistoIx = currHistogramIx + context;

                            entropy[context] = BitsEntropy(histograms[currHistoIx]);

                            for (int i = 0; i < 2; i++)
                            {
                                int ix = i * numContexts + context;
                                int lastHistogramIxValue = lastHistogramIx[i] + context;

                                var newHisto = new FrequencyList <T> {
                                    histograms[currHistoIx],
                                    histograms[lastHistogramIxValue]
                                };

                                combinedHisto[ix]   = newHisto;
                                combinedEntropy[ix] = BitsEntropy(combinedHisto[ix]);
                                diff[i]            += combinedEntropy[ix] - entropy[context] - lastEntropy[ix];
                            }
                        }

                        if (builder.TypeCount < maxBlockTypes && diff[0] > splitThreshold && diff[1] > splitThreshold)
                        {
                            byte nextBlockType = (byte)(builder.TypeCount);

                            builder.AddBlock(nextBlockType, blockSize);

                            lastHistogramIx[1] = lastHistogramIx[0];
                            lastHistogramIx[0] = nextBlockType * numContexts;

                            for (int context = 0; context < numContexts; context++)
                            {
                                lastEntropy[context + numContexts] = lastEntropy[context];
                                lastEntropy[context] = entropy[context];
                            }

                            currHistogramIx += numContexts;

                            if (currHistogramIx < histograms.Length)
                            {
                                histograms[currHistogramIx].Clear();
                            }

                            ++numBlocks;
                            blockSize       = 0;
                            mergeLastCount  = 0;
                            targetBlockSize = minBlockSize;
                        }
                        else if (diff[1] < diff[0] - 20.0)
                        {
                            builder.AddBlock(builder.Commands.Count >= 2 ? builder.Commands[^ 2].Type : (byte)0, blockSize);
        protected override (MetaBlock, BrotliGlobalState) Transform(MetaBlock.Compressed original, BrotliGlobalState state, BrotliCompressionParameters parameters)
        {
            var builder = new CompressedMetaBlockBuilder(original, state);

            var literals      = new List <Literal>(builder.GetTotalBlockLength(Category.Literal));
            var lengthCodes   = new List <InsertCopyLengthCode>(builder.GetTotalBlockLength(Category.InsertCopy));
            var distanceCodes = new List <DistanceCode>(builder.GetTotalBlockLength(Category.Distance));

            var distanceFreq       = new FrequencyList <DistanceCode>();
            var validDistanceCodes = new List <DistanceCode>(5);

            foreach (var command in original.Data.InsertCopyCommands)
            {
                literals.AddRange(command.Literals);
                state.OutputLiterals(command.Literals);

                if (command.CopyDistance == DistanceInfo.EndsAfterLiterals)
                {
                    lengthCodes.Add(command.Lengths.MakeCode(ImplicitDistanceCodeZero.PreferEnabled));
                    break;
                }

                if (!command.CopyDistance.FindCodes(original.Header.DistanceParameters, state, validDistanceCodes))
                {
                    lengthCodes.Add(command.Lengths.MakeCode(ImplicitDistanceCodeZero.ForceEnabled));
                }
                else
                {
                    DistanceCode distanceCode;

                    if (command.CopyDistance == DistanceInfo.ExplicitCodeZero)
                    {
                        distanceCode = DistanceCode.Zero;
                    }
                    else
                    {
                        distanceCode = validDistanceCodes.Count > 1 ? parameters.DistanceCodePicker(validDistanceCodes, distanceFreq) : validDistanceCodes[0];
                    }

                    distanceFreq.Add(distanceCode);
                    distanceCodes.Add(distanceCode);
                    lengthCodes.Add(command.Lengths.MakeCode(ImplicitDistanceCodeZero.Disable));
                }
            }

            var origLitCtxMap = builder.LiteralCtxMap;

            if (origLitCtxMap.TreeCount == 1)
            {
                Split(builder, Category.Literal, literals, 512, 400.0);

                builder.UseSameLiteralContextMode(LiteralContextMode.UTF8);
                builder.LiteralCtxMap = new ContextMapBuilder.Literals(builder).RepeatFirstBlockType(true).Build();
            }
            else
            {
                var literalContextMap  = Enumerable.Range(0, origLitCtxMap.ContextsPerBlockType).Select(index => origLitCtxMap.DetermineTreeID(0, index)).ToArray();
                var literalContextMode = builder.LiteralContextModes[0];

                var literalBuffer = RingBufferFast <byte> .From(0, 0);

                Split(builder, Category.Literal, literals, 512, 400.0, new BlockSplitter <Literal> .ContextInfo(literalContextMap, literal => {
                    literalBuffer.Push(literal.Value);
                    return(literalContextMode.DetermineContextID(literalBuffer.Front, literalBuffer.Back));
                }));

                builder.UseSameLiteralContextMode(literalContextMode);
                builder.LiteralCtxMap = new ContextMapBuilder.Literals(builder).Set(0, literalContextMap).RepeatFirstBlockType(true).Build();
            }

            Split(builder, Category.InsertCopy, lengthCodes, 1024, 500.0);
            Split(builder, Category.Distance, distanceCodes, 512, 100.0);

            builder.DistanceCtxMap = new ContextMapBuilder.Distances(builder).RepeatFirstBlockType(true).Build();

            return(builder.Build(parameters));
        }
Esempio n. 10
0
 /// <summary>
 /// Generates a canonical depth-limited Huffman tree using the provided <paramref name="symbolFrequencies"/>, and default depth limit of 15.
 /// </summary>
 public static HuffmanTree <T> FromSymbols(FrequencyList <T> symbolFrequencies)
 {
     return(FromSymbols(symbolFrequencies, DefaultMaxDepth));
 }
Esempio n. 11
0
 public void ExecuteAddFrequency()
 {
     FrequencyList.Add(NewFrequency);
     FrequencyList.Sort();
 }
Esempio n. 12
0
 public bool CanExecuteAddFrequency()
 {
     return(NewFrequency > 0.0 && !FrequencyList.Contains(NewFrequency));
 }
 public DistanceCode Pick(List <DistanceCode> picks, FrequencyList <DistanceCode> previouslySeen)
 {
     picks.RemoveAll(BlockedCodes.Contains);
     return(originalPicker(picks, previouslySeen));
 }
Esempio n. 14
0
 public PartialWordLookupJMDictDataSource(PartialWordLookup lookup, FrequencyList list)
 {
     this.lookup = lookup;
     this.list   = list;
 }
Esempio n. 15
0
    IEnumerator LoginRequest(string username, string password)
    {
        // Instantiate loading animation.
        Debug.Log ("Instantiating load animation");
        GameObject canvas = GameObject.FindGameObjectsWithTag ("canvas")[0];
        load = Instantiate (loadAnimation);
        load.transform.SetParent (canvas.transform);

        yield return TestSession();

        yield return SignIn(username,password);

        Debug.Log(sessionID);

        if (sessionID == 0) {
            loginFail();
        } else {
            yield return NativeLanguageRequest();
        }

        Debug.Log(sessionID);

        if(userNativeLanguage != null && userNativeLanguage != "") {
            yield return LearnedLanguageRequest();
        } else {
            loginFail();
        }

        if (userLearnedLanguage != null && userLearnedLanguage != "") {
            yield return RetrieveBookmarks();
        } else {
            loginFail();
        }

        if(userBookmarks == null) {
            loginFail();
        }

        // Store the session
        saveSession();

        //Loading up the word frequency list to be used in word selection
        frequencyList = new FrequencyList(userLearnedLanguage);
        frequencyList.initialize();

        Debug.Log(frequencyList.lang);
        //Go to main menu
        if(frequencyList.lang != null && frequencyList.lang != "") {
            Screen.orientation = ScreenOrientation.Landscape;
            SceneManager.LoadScene(1);
        } else {
            loginFail();
        }

        // Finalise loading animation.
        Debug.Log ("Destroying load animation");
        Destroy (load);
    }
Esempio n. 16
0
 public PartialWordLookupJMDictDataSource(JMDict jmdict, FrequencyList list)
 {
     this.jmdict = jmdict;
     this.list   = list;
 }