Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions spec/irt_ruby/rasch_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,12 @@
end
end

context "Deterministic seed" do
it "produces consistent results with the same seed" do
srand(123)
model1 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05)
context "Constructor seed" do
it "produces consistent results with the same seed option" do
model1 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05, seed: 123)
result1 = model1.fit

srand(123)
model2 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05)
model2 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05, seed: 123)
result2 = model2.fit

expect(result1[:abilities]).to eq(result2[:abilities])
Expand All @@ -179,10 +177,11 @@
it "handles a moderately large dataset without error" do
n_examinees = 20
n_items = 10
rng = Random.new(123)
big_data = Array.new(n_examinees) do
Array.new(n_items) { rand < 0.5 ? 1 : 0 }
Array.new(n_items) { rng.rand < 0.5 ? 1 : 0 }
end
model = described_class.new(big_data, max_iter: 300, learning_rate: 0.05)
model = described_class.new(big_data, max_iter: 300, learning_rate: 0.05, seed: 123)
expect { model.fit }.not_to raise_error

results = model.fit
Expand Down
15 changes: 7 additions & 8 deletions spec/irt_ruby/three_parameter_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,12 @@
end
end

context "Deterministic seed" do
it "produces consistent results with the same seed" do
srand(123)
model1 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05)
context "Constructor seed" do
it "produces consistent results with the same seed option" do
model1 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05, seed: 123)
result1 = model1.fit

srand(123)
model2 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05)
model2 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05, seed: 123)
result2 = model2.fit

expect(result1[:abilities]).to eq(result2[:abilities])
Expand All @@ -231,11 +229,12 @@
it "handles a moderately large dataset without error" do
n_examinees = 20
n_items = 8
rng = Random.new(123)
big_data = Array.new(n_examinees) do
Array.new(n_items) { rand < 0.5 ? 1 : 0 }
Array.new(n_items) { rng.rand < 0.5 ? 1 : 0 }
end

model = described_class.new(big_data, max_iter: 300, learning_rate: 0.05)
model = described_class.new(big_data, max_iter: 300, learning_rate: 0.05, seed: 123)
expect { model.fit }.not_to raise_error

results = model.fit
Expand Down
15 changes: 7 additions & 8 deletions spec/irt_ruby/two_parameter_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,12 @@
end
end

context "Deterministic seed" do
it "yields consistent results with the same seed" do
srand(123)
model1 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05)
context "Constructor seed" do
it "yields consistent results with the same seed option" do
model1 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05, seed: 123)
result1 = model1.fit

srand(123)
model2 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05)
model2 = described_class.new(data_array, max_iter: 200, learning_rate: 0.05, seed: 123)
result2 = model2.fit

expect(result1[:abilities]).to eq(result2[:abilities])
Expand All @@ -189,11 +187,12 @@
it "handles a moderately sized dataset without error" do
n_examinees = 20
n_items = 8
rng = Random.new(123)
big_data = Array.new(n_examinees) do
Array.new(n_items) { rand < 0.5 ? 1 : 0 }
Array.new(n_items) { rng.rand < 0.5 ? 1 : 0 }
end

model = described_class.new(big_data, max_iter: 300, learning_rate: 0.05)
model = described_class.new(big_data, max_iter: 300, learning_rate: 0.05, seed: 123)
expect { model.fit }.not_to raise_error

results = model.fit
Expand Down
Loading