Skip to content

Commit 0935c63

Browse files
committed
Addressing issue #18
1 parent 4e1ca26 commit 0935c63

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

BayesicFitting/source/UserModel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
__author__ = "Do Kester"
1212
__year__ = 2022
1313
__license__ = "GPL3"
14-
__version__ = "3.0.0"
14+
__version__ = "3.0.1"
1515
__url__ = "https://www.bayesicfitting.nl"
1616
__status__ = "Perpetual Beta"
1717

@@ -120,7 +120,7 @@ def __init__( self, npars, userResult, ndim=1, userPartial=None, userDeriv=None,
120120

121121
self.setMethod( "userResult", userResult )
122122

123-
super( ).__init__( npars, copy=copy, **kwargs )
123+
super( ).__init__( npars, ndim=ndim, copy=copy, **kwargs )
124124

125125
if copy is not None :
126126
setatt( self, "userPartial", copy.userPartial )
@@ -133,7 +133,7 @@ def __init__( self, npars, userResult, ndim=1, userPartial=None, userDeriv=None,
133133

134134
def copy( self ):
135135
""" Copy method. """
136-
return UserModel( self.npars, self.baseResult, copy=self )
136+
return UserModel( self.npars, self.baseResult, ndim=self.ndim, copy=self )
137137

138138
def setMethod( self, name, userMethod, numeric=None ) :
139139
if callable( userMethod ) :

BayesicFitting/test/TestUserModel.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def etalonDer( xdata, params ) :
7777
dd *= dd
7878
return - 2 * math.pi * params[0] * params[1] * params[2] * sx * numpy.cos( x ) / dd
7979

80+
def fitfunc(x, p):
81+
return x[:,0]*p[0] + x[:,1]*p[1] + p[2]
82+
83+
8084
class Test( unittest.TestCase ):
8185
"""
8286
Test harness for Models
@@ -120,6 +124,27 @@ def test2( self ):
120124
assertAE( m1.derivative( x, p ), m2.derivative( x, p ) )
121125

122126

127+
def test3( self ):
128+
print( "******USER MODEL 2***********************" )
129+
130+
# Make 10 random 2-dimensional points
131+
x = numpy.random.rand( 10, 2 )
132+
133+
# Make fake data + noise
134+
p = numpy.array( [1,2,3] )
135+
cleandata = fitfunc( x, p )
136+
noisedata = cleandata * numpy.random.normal( 1, 0.05, x.shape[0] )
137+
138+
# Find model parameters from noisy data
139+
model = UserModel( len(p), fitfunc, ndim=2 )
140+
fitter = Fitter( x, model )
141+
param = fitter.fit( noisedata )
142+
143+
self.assertTrue( model.ndim == 2 )
144+
print( param )
145+
146+
147+
123148

124149
@classmethod
125150
def suite( cls ):

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A package for model fitting and Bayesian evidence calculation.
44

55
We have a paper out in "Astronomy and Computing" about BayesicFitting.
6-
[Kester and Mueller (2021)](./references.md/#kester8).
6+
[Kester and Mueller (2021)](./docs/references.md/#kester8).
77

88
(In case you are wondering what that is about take a
99
quick look at [this example.]
@@ -14,6 +14,9 @@ DOI: 10.5281/zenodo.2597200
1414

1515

1616
## What's new.
17+
+ 05 Apr 2022 version 3.0.1
18+
* Addressing issue #18: UserModel does not work for multiple dimensions.
19+
1720
+ 07 Feb 2022 version 3.0.0
1821
* New classes: AstropyModel and UserModel
1922
* New class: NeuralNetUtilities

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
__version__ = '3.0.0'
3+
__version__ = '3.0.1'
44

55
with open("README.md", "r") as fh:
66
long_description = fh.read()

0 commit comments

Comments
 (0)