Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
python-RAT/cpp/RAT/calcDensity.cpp at pybind_demo · RascalSoftware/python-RAT · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
RascalSoftware
/
python-RAT
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
3
Code
Issues
3
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
pybind_demo
Breadcrumbs
python-RAT
/
cpp
/
RAT
/
calcDensity.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
165 lines (152 loc) · 5.14 KB
pybind_demo
Breadcrumbs
python-RAT
/
cpp
/
RAT
/
calcDensity.cpp
Copy path
Top
File metadata and controls
Code
Blame
165 lines (152 loc) · 5.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//
//
Non-Degree Granting Education License -- for use at non-degree
//
granting, nonprofit, education, and research organizations only. Not
//
for commercial or industrial use.
//
//
calcDensity.cpp
//
//
Code generation for function 'calcDensity'
//
//
Include files
#
include
"
calcDensity.h
"
#
include
"
RATMain_types.h
"
#
include
"
rt_nonfinite.h
"
#
include
"
scaledGaussPrior.h
"
#
include
"
coder_array.h
"
//
Function Definitions
namespace
RAT
{
void
calcDensity
(
const
::coder::array<real_T,
2U
> &x,
const
::coder::array<
real_T,
2U
> &fx,
const
struct13_T *DREAMPar,
const
::coder::
array<real_T,
2U
> &ratInputs_problemStruct_fitLimits,
const
::
coder::array<real_T,
2U
> &ratInputs_priors, ::coder::array<
real_T,
1U
> &log_L, ::coder::array<real_T,
1U
> &log_PR)
{
::coder::array<real_T,
2U
>
PR
;
::coder::array<real_T,
2U
> b_x;
int32_T i;
int32_T loop_ub;
int32_T loop_ub_tmp;
//
Now calculate the likelihood (not used) and log-likelihood (used)
//
---------------------------------------
//
For RAT, all the calculations are of the mvnpdf type, so remove the
//
other options.
//
------------------------------------ AVH
//
% If number of measurements larger than 0 --> simulation
//
if Meas_info.N > 0
//
//
% Initialize "res" (residual matrix)
//
res = NaN(Meas_info.N,DREAMPar.N);
//
//
% Loop over each model realization
//
for ii = 1 : DREAMPar.N
//
//
% We now calculate the error residual
//
res(:,ii) = (Meas_info.Y(:) - fx(1:Meas_info.N,ii));
//
//
end
//
//
else
//
//
% Do nothing, fx is a density or log-density returned by the PDF handle
//
//
end
//
----------------------- Calculate log-prior ----------------------------
//
No ABC --> regular priors (pdfs)
//
if ~DREAMPar.ABC
//
//
% Calculate the log-prior
//
if isfield(Par_info,'prior_marginal')
//
//
% Compute prior densities for each parameter in each sequence
//
for qq = 1 : DREAMPar.d
//
for zz = 1 : DREAMPar.N
//
% Compute prior density of proposal
//
PR(zz,qq) = max ( eval(char(strrep(Par_info.prior_marginal(qq),'rnd(','pdf(x(zz,qq),'))) , 1e-299 );
//
end
//
end
//
//
% Take the log of the densities and their sum
//
log_PR = sum ( log ( PR ) , 2 );
//
//
elseif isfield(Par_info,'mvnpdf')
//
RAT specific prior funtion (mvnpdf)
loop_ub_tmp =
static_cast
<int32_T>(DREAMPar->
N
);
PR
.
set_size
(
1
, loop_ub_tmp);
for
(i =
0
; i < loop_ub_tmp; i++) {
PR
[i] =
0.0
;
}
if
(loop_ub_tmp -
1
>=
0
) {
loop_ub = x.
size
(
1
);
}
//
Take log of any non-zero values..
log_PR.
set_size
(loop_ub_tmp);
for
(int32_T b_i{
0
}; b_i < loop_ub_tmp; b_i++) {
//
Loop over all the chains..
b_x.
set_size
(
1
, x.
size
(
1
));
for
(i =
0
; i < loop_ub; i++) {
b_x[i] = x[b_i + x.
size
(
0
) * i];
}
PR
[b_i] =
scaledGaussPrior
(b_x, ratInputs_problemStruct_fitLimits,
ratInputs_priors);
//
mvnpdf automatically goes over all pars
log_PR[b_i] =
0.0
;
}
i =
PR
.
size
(
1
);
for
(int32_T b_i{
0
}; b_i < i; b_i++) {
real_T d;
d =
PR
[b_i];
if
(d !=
0.0
) {
log_PR[b_i] = d;
//
log(PR(i)); % Does it even need to be log?
}
else
{
//
Otherwise keep the zero values
log_PR[b_i] =
0.0
;
}
}
//
log_PR = sum(log_PR(:)); % Enforce column vector
//
else
//
No use of prior --> set log-prior to zero (no effect in Metropolis)
//
log_PR = zeros ( DREAMPar.N , 1 );
//
//
end
//
//
//
else
//
//
Diagnostic Bayes --> if summary metric is defined as prior
//
if isfield(DREAMPar,'prior_handle')
//
//
Evaluate distance between observed and simulated summary metrics
//
for ii = 1 : DREAMPar.N
//
//
Calculate summary metrics for "fx"
//
S_sim = DREAMPar.prior_handle ( fx(:,ii) );
//
//
Now calculate log-density (not a true log-density! - but does not matter)
//
log_PR(ii,1) = max ( abs ( Meas_info.S(:) - S_sim(:) ) );
//
//
end
//
//
Regular ABC with summary metrics as likelihood function
//
else
//
//
log_PR = zeros ( DREAMPar.N , 1 );
//
//
end
//
//
end
//
--------------------- End Calculate log-prior ---------------------------
//
-------------------- Calculate log-likelihood ---------------------------
//
Loop over each model realization and calculate log-likelihood of each fx
log_L.
set_size
(loop_ub_tmp);
for
(i =
0
; i < loop_ub_tmp; i++) {
log_L[i] =
0.0
;
}
for
(int32_T ii{
0
}; ii < loop_ub_tmp; ii++) {
log_L[ii] = fx[ii];
}
//
------------------ End Calculate log-likelihood -------------------------
}
}
//
End of code generation (calcDensity.cpp)
You can’t perform that action at this time.