-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tao ad #130
Merged
Merged
Tao ad #130
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,25 @@ | ||
@inline apply(o::Sum, diags::Vector{Diagram{W}}) where {W<:Number} = sum(d.weight for d in diags) | ||
@inline apply(o::Prod, diags::Vector{Diagram{W}}) where {W<:Number} = prod(d.weight for d in diags) | ||
@inline apply(o::Sum, diag::Diagram{W}) where {W<:Number} = diag.weight | ||
@inline apply(o::Prod, diag::Diagram{W}) where {W<:Number} = diag.weight | ||
|
||
@inline eval(d::DiagramId) = error("eval for $d has not yet implemented!") | ||
|
||
######################### evaluator for KT representation ######################### | ||
function evalDiagNodeKT!(diag::Diagram, varK, varT, additional=nothing; eval=DiagTree.eval) | ||
if length(diag.subdiagram) == 0 | ||
# if hasproperty(diag.id, :extK) | ||
if (isnothing(varK) == false) && (isnothing(varT) == false) | ||
K = varK * diag.id.extK | ||
if isnothing(additional) | ||
diag.weight = eval(diag.id, K, diag.id.extT, varT) * diag.factor | ||
else | ||
diag.weight = eval(diag.id, K, diag.id.extT, varT, additional) * diag.factor | ||
end | ||
elseif isnothing(varK) | ||
if isnothing(additional) | ||
diag.weight = eval(diag.id, diag.id.extT, varT) * diag.factor | ||
else | ||
diag.weight = eval(diag.id, diag.id.extT, varT, additional) * diag.factor | ||
end | ||
elseif isnothing(varT) | ||
K = varK * diag.id.extK | ||
if isnothing(additional) | ||
diag.weight = eval(diag.id, K) * diag.factor | ||
else | ||
diag.weight = eval(diag.id, K, additional) * diag.factor | ||
end | ||
#@inline add( diags::Vector{Graph{F,W}}) where {F<:Number,W<:Number} = sum(d.weight for d in diags) | ||
@inline apply(::Type{Sum}, diags::Vector{Graph{F,W}}, factors::Vector{F}) where {F<:Number,W<:Number} = sum(d.weight*d.factor*f for (d,f) in zip(diags,factors) ) | ||
@inline apply(::Type{Prod}, diags::Vector{Graph{F,W}}, factors::Vector{F}) where {F<:Number,W<:Number} = prod(d.weight*d.factor*f for (d,f) in zip(diags,factors) ) | ||
@inline apply(o::Sum, diag::Graph{F,W}) where {F<:Number,W<:Number} = diag.weight | ||
@inline apply(o::Prod, diag::Graph{F,W}) where {F<:Number,W<:Number} = diag.weight | ||
|
||
# #@inline eval(d::DiagramId) = error("eval for $d has not yet implemented!") | ||
# # | ||
function evalGraph!(g::Graph) | ||
result = nothing | ||
for node in PostOrderDFS(g) | ||
if isleaf(node) | ||
node.weight = 1.0 ##Currently set to 1 just for test. In the future, probably the whole function is not needed since we have the compiler. | ||
else | ||
if isnothing(additional) | ||
diag.weight = eval(diag.id) * diag.factor | ||
else | ||
diag.weight = eval(diag.id, additional) * diag.factor | ||
end | ||
node.weight = apply(node.operator, node.subgraphs, node.subgraph_factors) | ||
#node.weight = add(node.subgraphs) * node.factor | ||
end | ||
else | ||
diag.weight = apply(diag.operator, diag.subdiagram) * diag.factor | ||
end | ||
return diag.weight | ||
end | ||
|
||
function evalKT!(diag::Diagram, varK, varT; eval=DiagTree.eval) | ||
for d in PostOrderDFS(diag) | ||
evalDiagNodeKT!(d, varK, varT; eval=eval) | ||
end | ||
return diag.weight | ||
end | ||
|
||
function evalKT!(diags::Vector{Diagram{W}}, varK, varT; eval=DiagTree.eval) where {W} | ||
for d in diags | ||
evalKT!(d, varK, varT; eval=eval) | ||
end | ||
# return W[d.weight for d in diags] | ||
end | ||
|
||
function evalKT!(df::DataFrame, varK, varT; eval=DiagTree.eval) where {W} | ||
for d in df[!, :diagram] | ||
evalKT!(d, varK, varT; eval=eval) | ||
end | ||
# return W[d.weight for d in df[!, :Diagram]] | ||
end | ||
|
||
######################### generic evaluator ######################### | ||
function evalDiagNode!(diag::Diagram, vargs...; eval=DiagTree.eval) | ||
if length(diag.subdiagram) == 0 | ||
diag.weight = eval(diag.id, vargs...) * diag.factor | ||
else | ||
diag.weight = apply(diag.operator, diag.subdiagram) * diag.factor | ||
end | ||
return diag.weight | ||
end | ||
|
||
function eval!(diag::Diagram, vargs...; eval=DiagTree.eval) | ||
for d in PostOrderDFS(diag) | ||
evalDiagNode!(d, vargs...; eval=eval) | ||
result = node.weight * node.factor | ||
end | ||
return diag.weight | ||
return result | ||
end | ||
|
||
function eval!(diags::Vector{Diagram{W}}, vargs...; eval=DiagTree.eval) where {W} | ||
for d in diags | ||
eval!(d, vargs...; eval=eval) | ||
end | ||
# return W[d.weight for d in diags] | ||
function evalGraph!(g::Number) | ||
return g | ||
end | ||
|
||
function eval!(df::DataFrame, vargs...; eval=DiagTree.eval) where {W} | ||
for d in df[!, :diagram] | ||
eval!(d, vargs...; eval=eval) | ||
end | ||
# return W[d.weight for d in df[!, :Diagram]] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename evalGraph! -> eval!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passing an additional vector "leaf" which contains the leaf weight.
eval! should have the same behavior as the compiled function