Sha256: 9e17dfad5e2fb8f7184fa5461590939f4d256bc94a29b58838495663658b36cc
Contents?: true
Size: 1 KB
Versions: 1
Compression:
Stored size: 1 KB
Contents
require "spec_helper" describe Anomaly::Detector do let(:data) { [[-1,-2],[0,0],[1,2]] } let(:ad) { Anomaly::Detector.new(data) } # mean = [0, 0], std = [1, 2] it "computes the right probability" do ad.probability([0,0]).should == 0.079577471545947667 end it "marshalizes" do expect{ Marshal.dump(ad) }.to_not raise_error end context "when standard deviation is 0" do let(:data) { [[1],[1]] } it "raises error" do expect{ ad }.to raise_error RuntimeError, "Standard deviation cannot be zero" end end context "when one training example" do let(:data) { [[1]] } it "raises error" do expect{ ad }.to raise_error RuntimeError, "Standard deviation cannot be zero" end end context "when data is a matrix" do let(:data) { [[-1,-2],[0,0],[1,2]] } let(:sample) { [rand, rand] } it "returns the same probability as an NMatrix" do ad.probability(sample).should == Anomaly::Detector.new(Matrix.rows(data)).probability(sample) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
anomaly-0.0.1 | spec/anomaly/detector_spec.rb |