Comments (8)
The function is missing a signature: what is the input shape and what is the output shape?
from quadpy.
I would blame the function signature. Answered in your original question on SO.
from quadpy.
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.
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.
Thanks for checking. The loss function works for the
cubature
-version. How can I rewrite it in such a way it also works forquadpy
?
Let's see the working variant.
from quadpy.
Thanks for checking. The loss function works for the
cubature
-version. How can I rewrite it in such a way it also works forquadpy
?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.
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.
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)
- ValueError: Need x21 < 0.3 (also why is the code encrypted?) HOT 8
- Problem with vectorization HOT 6
- Quadpy usage HOT 1
- The source code is not available HOT 1
- Status of package and licensing HOT 4
- Quadpy is now asking for a sigma license HOT 18
- Can't import HOT 8
- Orthopy version no longer supported HOT 9
- version of orthopy no longer supported HOT 5
- Return points and values for integrate_adaptive HOT 1
- Importing quadpy causes python to quit without any error message HOT 4
- Issue upgrading quadpy HOT 7
- Unable to find valid license for Sigma. HOT 3
- Recurrent issue with sigma license HOT 5
- NameError: name 'c2' is not defined HOT 3
- Quadpy RuntimeError HOT 7
- Adaptive multivariate integration over hypercubes HOT 9
- newest pip version not importable HOT 1
- the integrals with Heaviside function are very inaccurate HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quadpy.