Giter Club home page Giter Club logo

Comments (6)

cjekel avatar cjekel commented on May 22, 2024

I'm glad you like the library and thanks for spotting that something is wrong.

If you can give me a short code example so that I can reproduce the error, it would make my troubleshooting a bit easier. I'll see if I can fix this.

Thanks,
CJ

from piecewise_linear_fit_py.

cjekel avatar cjekel commented on May 22, 2024

I think I can replicate the error with the following code

import numpy as np
import pwlf

x = np.array((0.0,1.0,2.0))
y = np.array((0.0,1.0,1.5))

my_fit = pwlf.piecewise_lin_fit(x,y)
x0 = x.copy()
x0[1] = 1.
ssr = my_fit.fitWithBreaks(x0)

Error:

     90 
     91         #   calculate the sum of the square of residuals
---> 92         e = self.yData-yHat
     93         SSr = np.dot(e.T,e)
     94 
ValueError: operands could not be broadcast together with shapes (3,) (4,) 

If you change x0[1] to something other than 1.0 like 1.001 it works...

Nice find I'll try to fix

from piecewise_linear_fit_py.

half1red avatar half1red commented on May 22, 2024

Looks like the error I found.

I try to add a piece of code in fitWithBreaks, just before e = self.yData-yHat in order to get rid of the duplicates. It probably could be more synthetic. It seems to work in my situation.

    double_ind = []
    last_x = [arr[-1] for arr in sepDataX[:-1]]
    first_x = [arr[0] for arr in sepDataX[1:]]
    indices = []
    count = -1
    for arr in sepDataX:
        count += arr.size
        indices.append(count)
    for i, (x1, x2) in enumerate(zip(first_x, last_x)):
        if x1 == x2:
            double_ind.append(indices[i])
    yHat = np.delete(yHat, double_ind)

from piecewise_linear_fit_py.

cjekel avatar cjekel commented on May 22, 2024

Do the changes in 9d2cd3a fix your issue?

I think you were correct in your original post about aTest, bTest should be a strict greater than or less than.

I'd rather not search for duplicates manually as this may be computationally expensive, but your code should work.

from piecewise_linear_fit_py.

half1red avatar half1red commented on May 22, 2024

Yes, that seems to correct my issue. I have seen that you also corrected seperateDataX. That's nice, because it was causing trouble to predict in the same situation with breaks on data points.

Thank you very much for your quick answers!

from piecewise_linear_fit_py.

cjekel avatar cjekel commented on May 22, 2024

Thanks for pointing this out! If you run into further issues please let me know.

from piecewise_linear_fit_py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.