Skip to content
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

Proyecto: Población de Insectos #86

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8fe970b
Creación de carpeta
danmarurr Nov 15, 2016
65d5106
Juego con el mapeo
danmarurr Nov 22, 2016
2e874c4
Avances
danmarurr Nov 29, 2016
423d907
Primer intento
danmarurr Dec 3, 2016
f955b11
Código por correr
danmarurr Dec 4, 2016
07de4bc
Corrección
danmarurr Dec 4, 2016
e14d2d5
Avances chidos
danmarurr Dec 4, 2016
396d0bc
Gráfica 3D
danmarurr Dec 5, 2016
874ea3f
Agrego avance
Pablorv Dec 5, 2016
7241e1d
Correciones
danmarurr Dec 5, 2016
ee2fca6
Quito Untitled
Pablorv Dec 5, 2016
2740d2c
--all
cutsof Dec 5, 2016
2dc70d3
Avance
danmarurr Dec 5, 2016
0fb72da
../PabloProy/population.ipynb
cutsof Dec 5, 2016
c91f974
ProySofi/Untitled.ipynb
cutsof Dec 5, 2016
c886181
Agrego ultima version
Pablorv Dec 5, 2016
9807794
Agrego imagenes
Pablorv Dec 5, 2016
2eb18ea
Agrego imagenes
Pablorv Dec 5, 2016
a5cb852
Agrego anotaciones
Pablorv Dec 5, 2016
c8862f1
Mas Avances
danmarurr Dec 5, 2016
0dd1f7e
Agrego archivo con imagenes
Pablorv Dec 5, 2016
086ad5b
sofi
cutsof Dec 5, 2016
81dab34
Avance Final
danmarurr Dec 5, 2016
8a664c4
sofi
cutsof Dec 5, 2016
4875553
Mi parte de presentación
danmarurr Dec 5, 2016
598ecca
Merge pull request #2 from danmarurr/ProyPablo
danmarurr Dec 5, 2016
27cece6
Quito conflictos
danmarurr Dec 5, 2016
45efec0
Reacomodo
danmarurr Dec 5, 2016
97420a3
Merge pull request #3 from danmarurr/ProyDaniel
danmarurr Dec 5, 2016
b204677
Finalización
danmarurr Dec 5, 2016
716ebef
Correciones menores
danmarurr Dec 5, 2016
4144e49
Correción a README.md
danmarurr Dec 5, 2016
b99c7b5
Agrego correcciones sugeridas
Pablorv Dec 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions proys/InsectPopulation/AutomDiff_V2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#Modulo de Diferenciacion Automatica
#El siguiente modulo define la estructura de los objetos "duales" asi como las operaciones entre ellos.
#Autores: Daniel (https://github.com/danmarurr) y Fernanda (https://github.com/FernandaPerez)


__precompile__(true)

module AD
import Base: +, -, *, /, ^, ==

export Dual, xdual



type Dual{T<:Real}
# código:
fun :: T
der :: T
end

Dual(a, b) = Dual(promote(a, b) ...)
# Aqui se define un método que garantiza que el dual de un número cumple lo requerido
Dual(a) = Dual(a, zero(0))
# Aqui se define la función `xdual`, que se usará para identificar la variable independiente

function xdual(x0)
Dual(x0, one(x0))
end

# Definiendo operaciones cuando los argumentos son Duales
+(a::Dual, b::Dual) = Dual(a.fun + b.fun, a.der + b.der)
-(a::Dual, b::Dual) = Dual(a.fun - b.fun, a.der - b.der)
*(a::Dual, b::Dual) = Dual(a.fun * b.fun, a.der*b.fun + b.der*a.fun)
/(a::Dual, b::Dual) = Dual(a.fun / b.fun, (a.der - b.der*(a.fun/b.fun))/b.fun)
^{T<:Int}(a::Dual, α::T) = Dual(a.fun^α, α*a.fun^(α - 1)*a.der)
^{T<:Float64}(a::Dual, α::T) = Dual(a.fun^α, α*a.fun^(α - 1)*a.der)
^{T<:Rational}(a::Dual, α::T) = Dual(a.fun^α, α*a.fun^(α - 1)*a.der)
^{T<:Irrational}(a::Dual, α::T) = Dual(a.fun^α, α*a.fun^(α - 1)*a.der)
==(a::Dual, b::Dual) = (a.fun == b.fun && a.der == b.der)


# Definiendo operaciones cuando el argumento de la derecha es un número
+{T<:Real}(a::Dual, γ::T) = +(a, Dual(γ))
-{T<:Real}(a::Dual, γ::T) = -(a, Dual(γ))
*{T<:Real}(a::Dual, γ::T) = *(a, Dual(γ))
/{T<:Real}(a::Dual, γ::T) = /(a, Dual(γ))

# Definiendo operaciones cuando el argumento de la izquierda es un número

+{T<:Real}(γ::T, a::Dual) = +(Dual(γ), a)
-{T<:Real}(γ::T, a::Dual) = -(Dual(γ), a)
*{T<:Real}(γ::T, a::Dual) = *(Dual(γ), a)
/{T<:Real}(γ::T, a::Dual) = /(Dual(γ), a)


#Importamos todas las funciones para las cuales queremos definir su operacion
import Base: ^, exp, sqrt, cbrt, sin, cos, tan, cot, sec, csc, sinh, cosh, tanh, coth, sech, csch,
asin, acos, atan, acot, asec, acsc,
asinh, acosh, atanh, acoth, asech, acsch

#Vector con todos los símbolos asociados a las funciones trigométricas, exponenciales, etc. y sus respectivas
#derivadas
Vec_Func = [(:sin, :cos), (:cos, :(x -> -sin(x))), (:tan, :(x -> (sec(x))^2)), (:cot, :(x -> -(csc(x))^2)),
(:sec, :(x -> sec(x)*tan(x))), (:csc, :(x -> -csc(x)*cot(x))), (:sinh, :cosh), (:cosh, :sinh),
(:tanh, :(x -> (sech(x))^2)), (:coth, :(x -> -(csch(x))^2)), (:asin, :(x -> 1/sqrt(1-x^2))),
(:acos, :(x -> -1/sqrt(1-x^2))), (:atan, :(x -> 1/(1+x^2))), (:acot, :(x -> -1/(1+x^2))),
(:asec, :(x -> 1/(sqrt(x^2-1)*x))), (:acsc, :(x -> -1/(sqrt(x^2-1)*x))), (:asinh, :(x -> 1/sqrt(1+x^2))),
(:acosh, :(x -> 1/sqrt(x^2-1))), (:atanh, :(x -> 1/(1-x^2))), (:acoth, :(x -> 1/(1-x^2))),
(:asech, :(x -> 1/(x*sqrt(1-x^2)))), (:acsch, :(x -> -1/(x*sqrt(1+x^2)))), (:sqrt, :(x -> 1/(2*sqrt(x)))), (:exp, :exp),
(:cbrt, :(x -> 1/(3*x^(2/3))))]

#Casos especiales: los logarítmos y a^x
log(a::Dual) = Dual(log(a.fun), a.der/a.fun)
log{T<:Real}(b::T, a::Dual) = Dual(log(b,a.fun), a.der/(log(b)*a.fun))
^{T<:Real}(b::T, a::Dual) = Dual(b^a.fun, a.der*log(b)*b^a.fun)

#Loop para crear los nuevos métodos a partir de los símbolos
for r in 1:length(Vec_Func)
fn = Vec_Func[r][1] #El primer símbolo está asociado a la función
der = Vec_Func[r][2] #El segundo símbolo está asociado a la derivada de la función
ex = quote #Creamos una nueva expresión
function ($fn)(a::Dual) #Definimos fn(a::Dual)
fun = ($fn)(a.fun)
derv = ($der)(a.fun)
return Dual(fun, derv*a.der) #Aplicamos la regla de la cadena
end
end
@eval $ex #Evaluamos la expresión para crear el método
end




end

Loading