mathpack 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mathpack/approximation.rb +5 -6
- data/lib/mathpack/version.rb +1 -1
- data/spec/approximation_spec.rb +18 -13
- data/spec/sle_spec.rb +2 -2
- data/spec/statistics_spec.rb +16 -16
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4ff99464e0f1a06b1ba3c2d3423096577a3649d1
         | 
| 4 | 
            +
              data.tar.gz: e41163fd0942911d66072c0d1b579d83ba9cec75
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 73f068a79ab03282563afd02416d48e1d54fb70b1f88d8286e0ac918215070ee8f3cc674cb731dc12878073b5fd4b0f1bce9ada7818a4271fb9748209c0c7880
         | 
| 7 | 
            +
              data.tar.gz: 8287a6d59751b79d6e6ed2df1cebb1fcea04763618f104c838bd747e01c8e835fb657b47e815a246007e1988cf288c87c63690d4e3da6ff32657ee4149e4b75b
         | 
| @@ -1,5 +1,3 @@ | |
| 1 | 
            -
            require 'mathpack'
         | 
| 2 | 
            -
             | 
| 3 1 | 
             
            module Mathpack
         | 
| 4 2 | 
             
              module Approximation
         | 
| 5 3 | 
             
                def self.basic_fi(x, power)
         | 
| @@ -57,12 +55,13 @@ module Mathpack | |
| 57 55 |  | 
| 58 56 | 
             
                def self.generate_nodes(params = {})
         | 
| 59 57 | 
             
                  nodes = []
         | 
| 60 | 
            -
                   | 
| 58 | 
            +
                  i = 0
         | 
| 61 59 | 
             
                  loop do
         | 
| 62 | 
            -
                    nodes <<  | 
| 63 | 
            -
                     | 
| 64 | 
            -
                    break if  | 
| 60 | 
            +
                    nodes << params[:start] + i * params[:step]
         | 
| 61 | 
            +
                    i += 1
         | 
| 62 | 
            +
                    break if params[:start] + i * params[:step] > params[:end]
         | 
| 65 63 | 
             
                  end
         | 
| 64 | 
            +
                  nodes << params[:end] if nodes.last != params[:end]
         | 
| 66 65 | 
             
                  nodes
         | 
| 67 66 | 
             
                end
         | 
| 68 67 |  | 
    
        data/lib/mathpack/version.rb
    CHANGED
    
    
    
        data/spec/approximation_spec.rb
    CHANGED
    
    | @@ -9,30 +9,35 @@ describe 'Approximation' do | |
| 9 9 | 
             
                let(:values) { Mathpack::Approximation.fill_f(nodes){ |val| val**2 } }
         | 
| 10 10 |  | 
| 11 11 | 
             
                it 'should generate nodes' do
         | 
| 12 | 
            -
                  expect(nodes.length).to  | 
| 13 | 
            -
                  expect(nodes.first).to  | 
| 14 | 
            -
                  expect(nodes.last).to  | 
| 12 | 
            +
                  expect(nodes.length).to eq(41)
         | 
| 13 | 
            +
                  expect(nodes.first).to eq(x_start)
         | 
| 14 | 
            +
                  expect(nodes.last).to eq(x_end)
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                it 'should generate correct nodes' do
         | 
| 18 | 
            +
                  nodes = Mathpack::Approximation.generate_nodes(start: 0, end: 1, step: 0.001)
         | 
| 19 | 
            +
                  expect(nodes.last).to eq(1.0)
         | 
| 15 20 | 
             
                end
         | 
| 16 21 |  | 
| 17 22 | 
             
                it 'should fill function table' do
         | 
| 18 | 
            -
                  expect(values.length).to  | 
| 19 | 
            -
                  expect(values.last).to  | 
| 23 | 
            +
                  expect(values.length).to eq(nodes.length)
         | 
| 24 | 
            +
                  expect(values.last).to eq(nodes.last**2)
         | 
| 20 25 | 
             
                end
         | 
| 21 26 |  | 
| 22 27 | 
             
                it 'should print polynoms' do
         | 
| 23 | 
            -
                  expect(Mathpack::Approximation.print_polynom([5])).to  | 
| 24 | 
            -
                  expect(Mathpack::Approximation.print_polynom([2, 3])).to  | 
| 25 | 
            -
                  expect(Mathpack::Approximation.print_polynom([1, -1, 1])).to  | 
| 26 | 
            -
                  expect(Mathpack::Approximation.print_polynom([1, 3, 5])).to  | 
| 27 | 
            -
                  expect(Mathpack::Approximation.print_polynom([1, -2, 3, -4])).to  | 
| 28 | 
            -
                  expect(Mathpack::Approximation.print_polynom([1, 0, 1])).to  | 
| 28 | 
            +
                  expect(Mathpack::Approximation.print_polynom([5])).to eq('5')
         | 
| 29 | 
            +
                  expect(Mathpack::Approximation.print_polynom([2, 3])).to eq('2*x + 3')
         | 
| 30 | 
            +
                  expect(Mathpack::Approximation.print_polynom([1, -1, 1])).to eq('x^2 - x + 1')
         | 
| 31 | 
            +
                  expect(Mathpack::Approximation.print_polynom([1, 3, 5])).to eq('x^2 + 3*x + 5')
         | 
| 32 | 
            +
                  expect(Mathpack::Approximation.print_polynom([1, -2, 3, -4])).to eq('x^3 - 2*x^2 + 3*x - 4')
         | 
| 33 | 
            +
                  expect(Mathpack::Approximation.print_polynom([1, 0, 1])).to eq('x^2 + 1')
         | 
| 29 34 | 
             
                end
         | 
| 30 35 |  | 
| 31 36 | 
             
                it 'should approximate by polynom' do
         | 
| 32 37 | 
             
                  coefficients = Mathpack::Approximation.approximate_by_polynom(x: nodes, f: values, polynom_power: 2)
         | 
| 33 | 
            -
                  expect(coefficients).to  | 
| 38 | 
            +
                  expect(coefficients).to eq([1.0, 0.0, 0.0])
         | 
| 34 39 | 
             
                  coefficients = Mathpack::Approximation.approximate_by_polynom(x: nodes, f: values, polynom_power: 0)
         | 
| 35 | 
            -
                  expect(coefficients).to  | 
| 40 | 
            +
                  expect(coefficients).to eq([33.75])
         | 
| 36 41 | 
             
                end
         | 
| 37 42 | 
             
              end
         | 
| 38 43 | 
             
            end
         | 
    
        data/spec/sle_spec.rb
    CHANGED
    
    | @@ -9,7 +9,7 @@ describe 'SLE' do | |
| 9 9 | 
             
                let(:vector_b) { Matrix.row_vector([15, 30, 15])  }
         | 
| 10 10 |  | 
| 11 11 | 
             
                it 'should give correct answer' do
         | 
| 12 | 
            -
                  expect(Mathpack::SLE.solve(matrix: a, f: b)).to  | 
| 12 | 
            +
                  expect(Mathpack::SLE.solve(matrix: a, f: b)).to eq([-1.0, 2.0, 4.0])
         | 
| 13 13 | 
             
                end
         | 
| 14 14 |  | 
| 15 15 | 
             
                it 'should raise error' do
         | 
| @@ -17,7 +17,7 @@ describe 'SLE' do | |
| 17 17 | 
             
                end
         | 
| 18 18 |  | 
| 19 19 | 
             
                it 'should return vector if matrix class is given' do
         | 
| 20 | 
            -
                  expect(Mathpack::SLE.solve(matrix: matrix_a, f: vector_b)).to  | 
| 20 | 
            +
                  expect(Mathpack::SLE.solve(matrix: matrix_a, f: vector_b)).to eq(Matrix.row_vector [-1.0, 2.0, 4.0])
         | 
| 21 21 | 
             
                end
         | 
| 22 22 | 
             
              end
         | 
| 23 23 | 
             
            end
         | 
    
        data/spec/statistics_spec.rb
    CHANGED
    
    | @@ -7,61 +7,61 @@ describe 'Statistics' do | |
| 7 7 | 
             
                let(:stat) { Mathpack::Statistics.new(data) }
         | 
| 8 8 |  | 
| 9 9 | 
             
                it 'should calculate number of elements' do
         | 
| 10 | 
            -
                  expect(stat.number).to  | 
| 10 | 
            +
                  expect(stat.number).to eq(10)
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 13 | 
             
                it 'should calculate mean' do
         | 
| 14 | 
            -
                  expect(stat.mean).to  | 
| 14 | 
            +
                  expect(stat.mean).to eq(4.0)
         | 
| 15 15 | 
             
                end
         | 
| 16 16 |  | 
| 17 17 | 
             
                it 'should calculate variance' do
         | 
| 18 | 
            -
                  expect(stat.variance).to  | 
| 18 | 
            +
                  expect(stat.variance).to eq(3.8)
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                it 'should calculate skewness' do
         | 
| 22 | 
            -
                  expect(stat.skewness).to  | 
| 22 | 
            +
                  expect(stat.skewness).to eq(0.16199658190818222)
         | 
| 23 23 | 
             
                end
         | 
| 24 24 |  | 
| 25 25 | 
             
                it 'should calculate kurtosis' do
         | 
| 26 | 
            -
                  expect(stat.kurtosis).to  | 
| 26 | 
            +
                  expect(stat.kurtosis).to eq(1.925207756232687)
         | 
| 27 27 | 
             
                end
         | 
| 28 28 |  | 
| 29 29 | 
             
                it 'should calculate the minimal element' do
         | 
| 30 | 
            -
                  expect(stat.min).to  | 
| 30 | 
            +
                  expect(stat.min).to eq(1)
         | 
| 31 31 | 
             
                end
         | 
| 32 32 |  | 
| 33 33 | 
             
                it 'should calculate the maximal element' do
         | 
| 34 | 
            -
                  expect(stat.max).to  | 
| 34 | 
            +
                  expect(stat.max).to eq(7)
         | 
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 37 | 
             
                it 'should calculate first raw moment equal to mean' do
         | 
| 38 | 
            -
                  expect(stat.raw_moment(1)).to  | 
| 38 | 
            +
                  expect(stat.raw_moment(1)).to eq(stat.mean)
         | 
| 39 39 | 
             
                end
         | 
| 40 40 |  | 
| 41 41 | 
             
                it 'should calculate second central moment equal to variance' do
         | 
| 42 | 
            -
                  expect(stat.central_moment(2)).to  | 
| 42 | 
            +
                  expect(stat.central_moment(2)).to eq(stat.variance)
         | 
| 43 43 | 
             
                end
         | 
| 44 44 |  | 
| 45 45 | 
             
                it 'should calculate raw moments' do
         | 
| 46 | 
            -
                  expect(stat.raw_moment(3)).to  | 
| 46 | 
            +
                  expect(stat.raw_moment(3)).to eq(110.8)
         | 
| 47 47 | 
             
                end
         | 
| 48 48 |  | 
| 49 49 | 
             
                it 'should calculate central moments' do
         | 
| 50 | 
            -
                  expect(stat.central_moment(5)).to  | 
| 50 | 
            +
                  expect(stat.central_moment(5)).to eq(18.0)
         | 
| 51 51 | 
             
                end
         | 
| 52 52 |  | 
| 53 53 | 
             
                it 'should calculate empirical cdf values in points' do
         | 
| 54 | 
            -
                  expect(stat.empirical_cdf(stat.min - 0.1)).to  | 
| 55 | 
            -
                  expect(stat.empirical_cdf(stat.max + 0.1)).to  | 
| 56 | 
            -
                  expect(stat.empirical_cdf(stat.mean)).to  | 
| 54 | 
            +
                  expect(stat.empirical_cdf(stat.min - 0.1)).to eq(0.0)
         | 
| 55 | 
            +
                  expect(stat.empirical_cdf(stat.max + 0.1)).to eq(1.0)
         | 
| 56 | 
            +
                  expect(stat.empirical_cdf(stat.mean)).to eq(0.4)
         | 
| 57 57 | 
             
                end
         | 
| 58 58 |  | 
| 59 59 | 
             
                it 'should calculate empirical pdf values in points' do
         | 
| 60 | 
            -
                  expect(stat.empirical_pdf(stat.mean)).to  | 
| 60 | 
            +
                  expect(stat.empirical_pdf(stat.mean)).to eq(0.1882412842233359)
         | 
| 61 61 | 
             
                end
         | 
| 62 62 |  | 
| 63 63 | 
             
                it 'should find trend' do
         | 
| 64 | 
            -
                  expect(stat.trend(polynom_power: 2)).to  | 
| 64 | 
            +
                  expect(stat.trend(polynom_power: 2)).to eq('0.0075757575757576055*x^2 + 0.2681818181818179*x + 2.233333333333334')
         | 
| 65 65 | 
             
                end
         | 
| 66 66 | 
             
              end
         | 
| 67 67 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mathpack
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - maxmilan
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-02- | 
| 11 | 
            +
            date: 2015-02-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |