From 30ad9cb0fa5efc77e5ccafae9acb35056d503210 Mon Sep 17 00:00:00 2001 From: Alex Kholodniak Date: Sat, 8 Jun 2024 22:21:39 -0500 Subject: [PATCH] add custom parameters max_iter and tolerance --- lib/irt_ruby/rasch_model.rb | 6 +++--- lib/irt_ruby/three_parameter_model.rb | 6 +++--- lib/irt_ruby/two_parameter_model.rb | 6 +++--- spec/irt_ruby/rasch_model_spec.rb | 2 +- spec/irt_ruby/three_parameter_model_spec.rb | 2 +- spec/irt_ruby/two_parameter_model_spec.rb | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/irt_ruby/rasch_model.rb b/lib/irt_ruby/rasch_model.rb index 1afa447..8d0e22e 100644 --- a/lib/irt_ruby/rasch_model.rb +++ b/lib/irt_ruby/rasch_model.rb @@ -5,12 +5,12 @@ module IrtRuby # A class representing the Rasch model for Item Response Theory. class RaschModel - def initialize(data) + def initialize(data, max_iter: 1000, tolerance: 1e-6) @data = data @abilities = Array.new(data.row_count) { rand } @difficulties = Array.new(data.column_count) { rand } - @max_iter = 1000 - @tolerance = 1e-6 + @max_iter = max_iter + @tolerance = tolerance end def sigmoid(x) diff --git a/lib/irt_ruby/three_parameter_model.rb b/lib/irt_ruby/three_parameter_model.rb index cb5b1f2..309dc31 100644 --- a/lib/irt_ruby/three_parameter_model.rb +++ b/lib/irt_ruby/three_parameter_model.rb @@ -5,14 +5,14 @@ module IrtRuby # A class representing the Three-Parameter model for Item Response Theory. class ThreeParameterModel - def initialize(data) + def initialize(data, max_iter: 1000, tolerance: 1e-6) @data = data @abilities = Array.new(data.row_count) { rand } @difficulties = Array.new(data.column_count) { rand } @discriminations = Array.new(data.column_count) { rand } @guessings = Array.new(data.column_count) { rand * 0.3 } - @max_iter = 1000 - @tolerance = 1e-6 + @max_iter = max_iter + @tolerance = tolerance end def sigmoid(x) diff --git a/lib/irt_ruby/two_parameter_model.rb b/lib/irt_ruby/two_parameter_model.rb index 6d947b4..50b0ecd 100644 --- a/lib/irt_ruby/two_parameter_model.rb +++ b/lib/irt_ruby/two_parameter_model.rb @@ -5,13 +5,13 @@ module IrtRuby # A class representing the Two-Parameter model for Item Response Theory. class TwoParameterModel - def initialize(data) + def initialize(data, max_iter: 1000, tolerance: 1e-6) @data = data @abilities = Array.new(data.row_count) { rand } @difficulties = Array.new(data.column_count) { rand } @discriminations = Array.new(data.column_count) { rand } - @max_iter = 1000 - @tolerance = 1e-6 + @max_iter = max_iter + @tolerance = tolerance end def sigmoid(x) diff --git a/spec/irt_ruby/rasch_model_spec.rb b/spec/irt_ruby/rasch_model_spec.rb index 375f7ec..bd1c199 100644 --- a/spec/irt_ruby/rasch_model_spec.rb +++ b/spec/irt_ruby/rasch_model_spec.rb @@ -4,7 +4,7 @@ RSpec.describe IrtRuby::RaschModel do let(:data) { Matrix[[1, 0, 1], [0, 1, 0], [1, 1, 1]] } - let(:irt_model) { IrtRuby::RaschModel.new(data) } + let(:irt_model) { IrtRuby::RaschModel.new(data, max_iter: 2000) } describe "#sigmoid" do it "calculates the sigmoid of a value" do diff --git a/spec/irt_ruby/three_parameter_model_spec.rb b/spec/irt_ruby/three_parameter_model_spec.rb index 58cbd4c..abbcd15 100644 --- a/spec/irt_ruby/three_parameter_model_spec.rb +++ b/spec/irt_ruby/three_parameter_model_spec.rb @@ -4,7 +4,7 @@ RSpec.describe IrtRuby::ThreeParameterModel do let(:data) { Matrix[[1, 0, 1], [0, 1, 0], [1, 1, 1]] } - let(:model) { IrtRuby::ThreeParameterModel.new(data) } + let(:model) { IrtRuby::ThreeParameterModel.new(data, max_iter: 1500) } describe "#initialize" do it "initializes with data" do diff --git a/spec/irt_ruby/two_parameter_model_spec.rb b/spec/irt_ruby/two_parameter_model_spec.rb index 0ccd07a..92b6a18 100644 --- a/spec/irt_ruby/two_parameter_model_spec.rb +++ b/spec/irt_ruby/two_parameter_model_spec.rb @@ -4,7 +4,7 @@ RSpec.describe IrtRuby::TwoParameterModel do let(:data) { Matrix[[1, 0, 1], [0, 1, 0], [1, 1, 1]] } - let(:model) { IrtRuby::TwoParameterModel.new(data) } + let(:model) { IrtRuby::TwoParameterModel.new(data, max_iter: 3000) } describe "#initialize" do it "initializes with data" do