public Hypothesis Crossover(Hypothesis hypothesisA, Hypothesis hypothesisB) { var minLength = Math.Min(hypothesisA.String.Length, hypothesisB.String.Length); if (minLength == 0) { return hypothesisA.String.Length > hypothesisB.String.Length ? hypothesisA : hypothesisB; } var index = Program.MainRandom.Next(0, minLength); Hypothesis hypA; Hypothesis hypB; if (Program.MainRandom.NextDouble() > 0.5) { hypA = hypothesisA; hypB = hypothesisB; } else { hypA = hypothesisB; hypB = hypothesisA; } var firstPart = hypA.String.Substring(0, index); var secondPart = hypB.String.Substring(index, hypB.String.Length - index); var newString = "" + firstPart + secondPart; var newHypothesis = new Hypothesis { String = newString }; return newHypothesis; }
public int EvaluateHypothesis(Hypothesis h) { if (h.Evaluated) return h.Fitness; var fitness = 0; var minLength = Math.Min(TargetString.Length, h.String.Length); for (var i = 0; i < minLength; i++) { if (h.String[i] == TargetString[i]) { fitness += 20; } else { for (var j = 1; j < 3; j++) { if (h.String[Math.Min(h.String.Length-1, i + j)] == TargetString[i]) { fitness += 10 - j; break; } if (h.String[Math.Max(0, i - j)] != TargetString[i]) continue; fitness += 10 - j; break; } } } fitness -= Math.Abs(TargetString.Length - h.String.Length)*2; h.Evaluated = true; return fitness; }
/// <summary> /// Constructs a Z test. /// </summary> /// <param name="sampleMean">The sample's mean.</param> /// <param name="sampleStdDev">The sample's standard deviation.</param> /// <param name="hypothesizedMean">The hypothesized value for the distribution's mean.</param> /// <param name="samples">The sample's size.</param> /// <param name="type">The type of hypothesis to test.</param> /// public ZTest(double sampleMean, double sampleStdDev, double hypothesizedMean, int samples, Hypothesis type) { double stdError = Tools.StandardError(samples, sampleStdDev); double z = (hypothesizedMean - sampleMean) / stdError; this.init(z, type); }
public ActionResult DeleteConfirmed(long id) { Hypothesis hypothesis = db.Hypothesis.Single(h => h.id == id); db.Hypothesis.DeleteObject(hypothesis); db.SaveChanges(); return(RedirectToAction("Index")); }
public void RejectHypothesis(Hypothesis h) { CurrentHypotheses.Remove(h); HypothesesChanged.Invoke(); PastHypotheses.Add(h); UILog.instance.Log("<i>[Theory rejected]</i>: " + h.Title); OnHypothesisRejected(h); }
/// <summary> /// Constructs a Z test. /// </summary> /// <param name="samples">The data samples from which the test will be performed.</param> /// <param name="hypothesizedMean">The constant to be compared with the samples.</param> /// <param name="type">The type of hypothesis to test.</param> /// public ZTest(double[] samples, double hypothesizedMean, Hypothesis type) { double mean = Tools.Mean(samples); double stdDev = Tools.StandardDeviation(samples, mean); double stdError = Tools.StandardError(samples.Length, stdDev); double z = (hypothesizedMean - mean) / stdError; this.init(z, type); }
public static CompareTwoStreamsResult CompareTwoStreams(Queue q1, Queue q2) { double t1 = q1.Sum(), t2 = q2.Sum(); int n1 = q1.Count, n2 = q2.Count; double R = n1 * t2 / n2 / t1; return(new CompareTwoStreamsResult(Hypothesis.Fisher(R, 2 * n2, 2 * n1))); }
/// <summary> /// Constructs a Z test. /// </summary> public ZTest(double mean, double stdDev, double x, int samples, Hypothesis hypothesis) { double stdError = Tools.StandardError(samples, stdDev); this.Statistic = (x - mean) / stdError; this.Hypothesis = hypothesis; this.compute(); }
public static CompareStreamsResult CompareStreams(IEnumerable <Queue> qs) { int n0 = qs.Sum(x => x.Count); double t0 = qs.Sum(x => x.Sum()); double H = 2 * (qs.Sum(x => x.Count * Math.Log(x.Count / x.Sum())) - n0 * Math.Log(n0 / t0)); return(new CompareStreamsResult(Hypothesis.ChiSquare(H, qs.Count() - 1))); }
public void InsertOrUpdate(Hypothesis hypothesis) { if (hypothesis.id == default(long)) { // New entity db.Hypothesis.AddObject(hypothesis); } else { // Existing entity db.Hypothesis.Attach(hypothesis); db.ObjectStateManager.ChangeObjectState(hypothesis, EntityState.Modified); } }
public ActionResult Create(Hypothesis hypothesis) { if (ModelState.IsValid) { db.Hypothesis.AddObject(hypothesis); db.SaveChanges(); return RedirectToAction("Index"); } return View(hypothesis); }
void OnHypothesisAccepted(Hypothesis h) { if (h == Data.AllHypotheses ["eyes"]) { UILog.instance.Log("<b>Dude:</b> Makes sense"); } if (h == Data.AllHypotheses ["hungover"]) { UILog.instance.Log("<b>Dude:</b> Sure feels like it"); } }
public Task <Hypothesis> GetHypothesisAsync(double[] data, double a) { if (a <= 0) { return(Task.FromException <Hypothesis>(new ArithmeticException())); } var result = new Hypothesis(data, a); return(Task.FromResult(result)); }
public ActionResult Edit(Hypothesis hypothesis) { if (ModelState.IsValid) { db.Hypothesis.Attach(hypothesis); db.ObjectStateManager.ChangeObjectState(hypothesis, EntityState.Modified); db.SaveChanges(); return RedirectToAction("Index"); } return View(hypothesis); }
public ActionResult Edit(Hypothesis hypothesis) { if (ModelState.IsValid) { db.Hypothesis.Attach(hypothesis); db.ObjectStateManager.ChangeObjectState(hypothesis, EntityState.Modified); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hypothesis)); }
/// <summary> /// Constructs a Z test. /// </summary> /// <param name="samples">The data samples from which the test will be performed.</param> /// <param name="x">The constant to be compared with the samples.</param> /// <param name="hypothesis">The hypothesis to test.</param> public ZTest(double[] samples, double x, Hypothesis hypothesis) { double mean = Tools.Mean(samples); double stdDev = Tools.StandardDeviation(samples, mean); double stdError = Tools.StandardError(samples.Length, stdDev); this.Statistic = (x - mean) / stdError; this.Hypothesis = hypothesis; this.compute(); }
public async Task <IActionResult> Create([Bind("Id,Name,Content,Explanation")] Hypothesis hypothesis) { if (ModelState.IsValid) { _context.Add(hypothesis); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(hypothesis)); }
public ActionResult Create(Hypothesis hypothesis) { if (ModelState.IsValid) { db.Hypothesis.AddObject(hypothesis); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hypothesis)); }
private void addHypothesis(Hypothesis hypothesis) { HypothesisTabControl Hypothesis = new HypothesisTabControl(hypothesis); Hypothesis.Dock = DockStyle.Top; Hypothesis.Height = 55; Hypothesis.Visible = true; Hypothesis.PropertyChanged += PropretyChanged; this.panelSurveyTableContent.Controls.Add(Hypothesis); this.panelSurveyTableContent.Controls.SetChildIndex(Hypothesis, 0); }
public async Task <bool> Stop() { bool result = await StopRecognizerThread(); if (result) { System.Diagnostics.Debug.WriteLine(TAG, "Stop recognition"); Hypothesis hypothesis = _decoder.Hyp(); OnResult(hypothesis, true); } return(!result); }
public bool Stop() { bool result = StopRecognizerThread(); if (result) { Log.Debug(TAG, "Stop recognition"); Hypothesis hypothesis = _decoder.Hyp(); OnResult(hypothesis, true); } return(!result); }
public void AcceptHypothesis(Hypothesis h) { if (h.ResultingFact != null) { DiscoverFact(h.ResultingFact); } CurrentHypotheses.Remove(h); HypothesesChanged.Invoke(); PastHypotheses.Add(h); UILog.instance.Log("<i>[Confirmed]</i>: " + h.Title); OnHypothesisAccepted(h); }
public int EvaluateHypothesis(Hypothesis h) { if (h.Evaluated) return h.Fitness; var fitness = 0; var minLength = Math.Min(TargetString.Length, h.String.Length); for (var i = 0; i < minLength; i++) { if(h.String[i] == TargetString[i]) fitness += 5; } fitness -= Math.Abs(TargetString.Length - h.String.Length); h.Evaluated = true; return fitness; }
/// <summary> /// This occurs on asynchronous basis /// </summary> /// <param name="Q"></param> /// <param name="A"></param> private void AsyncResultChanged(string Q, string A) { this.Dispatcher.Invoke(() => { if (A.StartsWith("SUDO:") == false) { //Play results audio AudioHandler.Results(); //Hide the spinner Spinner.Hide(); //Hide the hypothesis var da = new DoubleAnimation(0, TimeSpan.FromMilliseconds(500)); Hypothesis.BeginAnimation(OpacityProperty, da); ResultSheet.Visibility = Visibility.Visible; var sa = FindResource("ResultsAnimation") as Storyboard; sa.Begin(); //Speak the answer OpenSpeak.Speak(A); q_label.Content = "\"" + Q + "\""; a_label.Text = A; } else { //Play results audio AudioHandler.Results(); //Hide the spinner Spinner.Hide(); //Hide the hypothesis var da = new DoubleAnimation(0, TimeSpan.FromMilliseconds(500)); Hypothesis.BeginAnimation(OpacityProperty, da); ResultSheet.Visibility = Visibility.Visible; var sa = FindResource("ResultsAnimation") as Storyboard; sa.Begin(); //Speak the answer OpenSpeak.Speak(A.Replace("SUDO:", "")); q_label.Content = "\"" + Q + "\""; a_label.Text = "Here's what I've got"; } }); }
private void buttonAddHypothesis_Click(object sender, EventArgs e) { using (var form = new AddHypothesisForm(this.viewModel.factors, this.viewModel.hypotheses)) { var result = form.ShowDialog(); if (result == DialogResult.OK) { Hypothesis hypothesis = new Hypothesis { number = this.viewModel.hypotheses.Count, secondFactor = form.viewModel.selectedArrival.title, firstFactor = form.viewModel.selectedStart.title }; this.viewModel.hypotheses.Add(hypothesis); this.addHypothesis(hypothesis); } } }
public bool DeleteHypothesis(Hypothesis faction) { using (var connection = new SqlConnection(System.Configuration.ConfigurationManager .ConnectionStrings["DefaultConnection"].ConnectionString)) { string sql = "DELETE FROM Hypothesis WHERE HypothesisID = @HypothesisId;"; var rowsAffected = connection.Query <int>(sql, faction).SingleOrDefault(); if (rowsAffected > 0) { return(true); } } return(false); }
public bool AddHypothesis(Hypothesis faction) { using (var connection = new SqlConnection(System.Configuration.ConfigurationManager .ConnectionStrings["DefaultConnection"].ConnectionString)) { string sql = "INSERT INTO Hypothesis(HypothesisID, Name, Description, FactionID) VALUES(@HypothesisId, @Name, @Description, @FactionId);"; var rowsAffected = connection.Query <int>(sql, faction).SingleOrDefault(); if (rowsAffected > 0) { return(true); } } return(false); }
private void GenerateHypothesesFromScratch(TestFieldModel testFieldModel) { var random = new Random(); var hypotheses = new List <Hypothesis>(); for (int i = 0; i < maxHypothesisCount; i++) { var newX = (int)(random.NextDouble() * testFieldModel.Width); var newY = (int)(random.NextDouble() * testFieldModel.Height); var newAngle = (int)(random.NextDouble() * 360 - 180); var hypothesis = new Hypothesis(newX, newY, newAngle); hypothesis.Weight = 1 / maxHypothesisCount; hypotheses.Add(hypothesis); } testFieldModel.GameObjects.AddRange(hypotheses); }
private void init(double statistic, Hypothesis type) { this.Statistic = statistic; this.Hypothesis = type; if (this.Hypothesis == Hypothesis.TwoTail) { this.PValue = 2.0 * NormalDistribution.Standard. DistributionFunction(-System.Math.Abs(Statistic)); } else { this.PValue = NormalDistribution.Standard. DistributionFunction(-System.Math.Abs(Statistic)); } }
public Task <Hypothesis> GetHypothesisAsync(string rawData, double a) { if (string.IsNullOrEmpty(rawData)) { return(Task.FromException <Hypothesis>(new ArgumentNullException())); } if (a <= 0) { return(Task.FromException <Hypothesis>(new ArithmeticException())); } var data = Utils.StringToNumber(rawData); var result = new Hypothesis(data, a); return(Task.FromResult(result)); }
private double GetNewWeight(TestFieldModel testFieldModel, Hypothesis hypothesis, double[] distancesFromSensors) { double result = 1; var distancesForHypothesis = CalculateDistanceToBeacons(hypothesis, testFieldModel); for (int i = 0; i < distancesFromSensors.Length; i++) { var expected = distancesFromSensors[i]; if (expected < 0) { continue; } var recieved = distancesForHypothesis[i]; result *= GetWeightFromNormalDistribution(recieved, expected, sensorsEps); } return(result); }
/// <summary> /// Occurs when the result has come back to MainWindow /// </summary> /// <param name="Q">The Question / Query asked by the user</param> /// <param name="A">The result for it</param> private void HandleResult(string Q, string A) { //Hide the spinner Spinner.Hide(); //Hide the hypothesis var da = new DoubleAnimation(0, TimeSpan.FromMilliseconds(500)); Hypothesis.BeginAnimation(OpacityProperty, da); ResultSheet.Visibility = Visibility.Visible; var sa = FindResource("ResultsAnimation") as Storyboard; sa.Begin(); q_label.Content = "\"" + Q + "\""; a_label.Text = A; }
/// <summary> /// Run Ransac /// </summary> /// <param name="max_iter">Maximum number of iterations to generate hypothesis</param> /// <param name="max_distance">Maximum distance threshold to qualify sample as inlier</param> public Hypothesis Run(int max_iter, double max_distance, int min_consensus_size, IRansacModelConstraint constraints) { Hypothesis final = null; int i = 0; while (i < max_iter && final == null) { Hypothesis h = new Ransac <T> .Hypothesis(_samples); this.BuildHypothesis(h, max_distance, constraints); if (h.ConsensusIds.Count >= min_consensus_size) { final = h; } ++i; } return(final); }
public void gameOver() { showDialog(gameOverDialog); string dialogText = "You got so old that you have to retire from scientific resaerch."; if (characters[currPlayer].getNumPublication() == 0) { dialogText += "You have dedicated your whole life to scientific research yet you could not publish any results...\n\n" + "Your sacrifice of your whole life has soon been forgotten by human beings, as only results matter.\n\n" + "Thanks for playing!"; } else if (characters[currPlayer].getNumPublication() <= 3) { dialogText += "You have dedicated your whole life to scientific research but you could only publish " + characters[currPlayer].getNumPublication() + " results:\n\n"; foreach (object idx in characters[currPlayer].publishedFindings) { int hidx = (int)idx; Hypothesis hyp = ResourceLibrary.hypothesisLib[hidx]; dialogText += hyp.content + "\n"; } dialogText += "Don't worry, at least you left your name in human history.\n"; dialogText += "Your final fame: " + characters[currPlayer].getFame() + "\n\n" + "Thanks for playing!"; } else { dialogText += "You have dedicated your whole life to scientific research. In your honorable life as a scientist, you have published " + characters[currPlayer].getNumPublication() + " results, such as\n\n"; int count = 0; foreach (object idx in characters[currPlayer].publishedFindings) { int hidx = (int)idx; Hypothesis hyp = ResourceLibrary.hypothesisLib[hidx]; dialogText += hyp.content + "\n"; count += 1; if (count >= 3) { break; } } dialogText += "Human beings will forever remember your contribution to science!\n"; dialogText += "Your final fame: " + characters[currPlayer].getFame() + "\n\n" + "Thanks for playing!"; } }
public void investLifeInHypothesis() { int gridIdx = characters[currPlayer].getGridLoc(); HypothesisGrid grid = map.getMapGrids()[gridIdx].GetComponent <HypothesisGrid>(); Hypothesis hyp = ResourceLibrary.hypothesisLib[grid.hypothesisIdx]; characters[currPlayer].loseLife(hyp.numYears); // We now assume that each hypothesis grid can only be occupied by one player, so the following can be simplified if (grid.investigation.ContainsKey(currPlayer)) { grid.investigation[currPlayer] += hyp.numYears; } else { grid.investigation.Add(currPlayer, hyp.numYears); } playSFX(Resources.Load <AudioClip>(ResourceLibrary.randomEventSFX)); map.getMapGrids()[gridIdx].GetComponent <SpriteRenderer>().color = characterColorMarks[currPlayer]; }
public static ProbPieceConstIntensityResult ProbPieceIntensity(PieceConstIntensityResult res) { int i = 0, cls = 0; List <ProbPieceConstIntensityClassResult> newlst = new List <ProbPieceConstIntensityClassResult>(); while (i < res.Results.Count) { cls++; List <PieceConstIntensityClassResult> lst = new List <PieceConstIntensityClassResult>(); lst.Add(res.Results[i]); if (i + 1 == res.Results.Count) { newlst.Add(new ProbPieceConstIntensityClassResult(lst, cls, res.Results[i].ConfInterval.Value)); break; } int nextNs = res.Results[i].Number; double nextL = res.Results[i].ConfInterval.Value; do { int _ns = nextNs, ns = res.Results[i + 1].Number; double _l = nextL, l = res.Results[i + 1].ConfInterval.Value; double t = (l - _l) / Math.Sqrt((_ns - 1) * l * l + (ns - 1) * _l * _l) * Math.Sqrt((ns * _ns * (ns + _ns - 2)) / (ns + _ns)); Hypothesis h = Hypothesis.Student(t, ns + _ns - 2); if (h.IsAccepted) { nextNs += ns; nextL = (ns * l + _ns * _l) / (ns + _ns); lst.Add(res.Results[i + 1]); i++; } if (!h.IsAccepted || i + 1 == res.Results.Count) { lst.ForEach(x => x.ConfInterval.ChangeValue(nextL)); newlst.Add(new ProbPieceConstIntensityClassResult(lst, cls, nextL)); i++; break; } } while (true); } return(new ProbPieceConstIntensityResult(newlst)); }
public int EvaluateHypothesis(Hypothesis h) { if (h.Evaluated) return h.Fitness; var fitness = 10000; var hIndex = 0; var endScan = false; if (h.String.Length > 0) { foreach (var charToFind in TargetString) { while (h.String[hIndex] != charToFind) { hIndex++; fitness -= 1; if (hIndex < h.String.Length) continue; endScan = true; break; } if (endScan) break; fitness += 20; } } fitness -= Math.Abs(TargetString.Length - h.String.Length); h.Evaluated = true; return fitness; }
public Hypothesis Crossover(Hypothesis hypothesisA, Hypothesis hypothesisB) { var sb = new StringBuilder(); var maxLength = Math.Max(hypothesisA.String.Length, hypothesisB.String.Length); for (var i = 0; i < maxLength; i++) { if (i >= hypothesisA.String.Length) { sb.Append("" + hypothesisB.String[i]); continue; } if (i >= hypothesisB.String.Length) { sb.Append("" + hypothesisA.String[i]); continue; } if (Program.MainRandom.NextDouble() > 0.5) { sb.Append("" + hypothesisA.String[i]); } else { sb.Append("" + hypothesisB.String[i]); } } var newHypothesis = new Hypothesis(); newHypothesis.String = sb.ToString(); return newHypothesis; }
/// <summary> /// Constructs a Z test. /// </summary> /// <param name="statistic">The test statistic, as given by (x-μ)/SE.</param> /// <param name="type">The type of hypothesis to test.</param> /// public ZTest(double statistic, Hypothesis type) { this.init(statistic, type); }