Specifying new priors¶
You can specify new priors by subclassing blendz.model.ModelBase
, redefining
the four functions that return the priors and instantiating your new model for blendz.photoz
.
Creating a new model class¶
Your new class should have the following basic layout:
from blendz.model import ModelBase
class MyNewModel(ModelBase):
#Optional:
def __init__(self, new_prior_params, **kwargs):
#Run the setup defined in ModelBase
super(MyNewModel, self).__init__(**kwargs)
#Do some other setup with your new_prior_parameters
#Mandatory:
def lnPrior(self, redshift, magnitude):
#Definition of P(z_a, t_a, m_0a) for all t_a
return 0.
#Optional:
def correlationFunction(self, redshifts):
#Definition of xi({z})
return 0.
#Optional:
def calibrate(self, photometry, cached_likelihood, **kwargs):
return 0.
A few things to note:
- The
__init__
function is optional but allows you to define additional setup tasks that are done when your model is instantiated. It is important you call the superclass__init__
if you define this. - The
correlationFunction
function is also optional. The functionself.comovingSeparation(z_lo, z_hi)
defined inModelBase
may be helpful. - While
__init__
is optional, you must redefinelnPrior
. This function takes afloat
for both the redshift and magnitude, and returns anumpy.array
of the natural log of the prior for each template type (not each template). Theself.possible_types
attribute is a list of the possible types, where each element is a string with the name of that type. These are automatically read from the template set file supplied at runtime. - The
**kwargs
get passed byModelBase
toConfiguration
, allowing you to edit the configuration like otherblendz
classes using keyword arguments. - The
redshift
,magnitude
andcomponent_ref_mag
arguments passed to natural-log prior functions are floats, while theredshifts
argument incorrelationFunction
is a 1Dnumpy
array. - The
calibrate
function is also optional. This takes as arguments ablendz.photometry.Photometry
object and anumpy.array
of shape(num_galaxies, num_templates)
filled with the likelihood. This function is called by theblendz.Photoz.calibrate(**kwargs)
function, with any keyword arguments passed to the function here. There is no return value for this function; the default model writes the resulting parameters to a configuration file that can be read byblendz.Photoz
.
Using the new model¶
The new model can simply be instantiated and passed to blendz.Photoz
as a keyword argument.
new_model = MyNewModel(new_prior_params=42, template_set='BPZ6')
pz = blendz.Photoz(model=new_model)