Giter Club home page Giter Club logo

Comments (8)

maciejskorski avatar maciejskorski commented on June 20, 2024 1

The function is missing a signature: what is the input shape and what is the output shape?

from quadpy.

maciejskorski avatar maciejskorski commented on June 20, 2024

I would blame the function signature. Answered in your original question on SO.

from quadpy.

nschloe avatar nschloe commented on June 20, 2024

Your loss_function is a bit weird: Whenever p is less than a given value, the return value is an array, otherwise it's 0. That doesn't make sense. If your function really is 0-or-1, Gaussian integration isn't well suited to the problem either.

Also, you probably mean to use quadpy.quad instead of quadpy.c1.integrate_adaptive.

I'll release a new quadpy version shortly which will feature better error messages.

from quadpy.

HJA24 avatar HJA24 commented on June 20, 2024

Thanks for checking. The loss function works for the cubature-version. How can I rewrite it in such a way it also works for quadpy?

from quadpy.

nschloe avatar nschloe commented on June 20, 2024

Thanks for checking. The loss function works for the cubature-version. How can I rewrite it in such a way it also works for quadpy?

Let's see the working variant.

from quadpy.

HJA24 avatar HJA24 commented on June 20, 2024

Thanks for checking. The loss function works for the cubature-version. How can I rewrite it in such a way it also works for quadpy?

Let's see the working variant.

The code can be found in the first post of this topic. Here it is

from cubature import cubature
import numpy as np


class Kelly:
    def __init__(self):
        self.odds = 1.952
        self.kelly = 0.08961344537815132
        self.i = 0.001
        self.f = np.arange(0, 1 + self.i, self.i).flatten()
        self.c1 = 1
        self.c2 = 2
        self.k = 1.5

    def loss_function(self, p):
        p = p[:, 0]
        loss_function = np.where(np.less(p[:, None], (self.f * self.odds - 1) + 1 / self.odds),
                                (self.c1 + self.c2) * abs(self.f - self.kelly) ** self.k, 
                                 0)
        return loss_function

    def integrate_vec(self):
        xmin = np.zeros(len(self.f))
        xmax = np.array([self.f * (self.odds - 1) + 1 / self.odds]).flatten()
        vals, errors = cubature(func=self.loss_function,
                                ndim=1,
                                fdim=len(self.f),
                                xmin=xmin,
                                xmax=xmax,
                                vectorized=True)
        return vals, errors


kelly = Kelly()
vals, errors = kelly.integrate_vec()
print(vals)
# [0.         0.         0.         ... 1.3305999  1.3327977  1.33499671]

from quadpy.

HJA24 avatar HJA24 commented on June 20, 2024

The function is missing a signature: what is the input shape and what is the output shape?

The input- and output shape are equal to (1, len(self.f))

from quadpy.

nschloe avatar nschloe commented on June 20, 2024

I just spent some time looking at the functions and it's not entirely clear to me what you're trying to do mathematically. Your loss_function gets a vector of shape (n,), and returns an array of shape (n, 1001). Those are the characteristics of a vector-valued function on a 1D interval. Is this correct?

I've also improved the error messages; they should be more helpful for your use case now.

from quadpy.

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.