Code Monkey home page Code Monkey logo

Comments (12)

LebedevRI avatar LebedevRI commented on June 28, 2024

Measurements.derivative.(x^2*y^2+2*x^3*y, [x, y])

That is a weird call, where did you get it?
derivative takes either a single Measurement argument + tag, or two Measurement arguments:

# Derivative and Gradient
derivative(a::Measurement{F},
tag::Tuple{T, T, UInt64}) where {F<:AbstractFloat, T<:AbstractFloat} =
get(a.der, tag, zero(F))
"""
derivative(x::Measurement, y::Measurement)
Return the value of the partial derivative of `x` with respect to the
independent measurement `y`, calculated on the nominal value of `y`. Return
zero if `x` does not depend on `y`.
Use `Measurements.derivative.(x, array)` to calculate the gradient of `x` with respect to an
array of independent measurements.
"""
derivative(a::Measurement, b::Measurement) =
derivative(a, (b.val, b.err, b.tag))

I'm not sure what you are trying to do, more generally.
#144 might be relevant.

from measurements.jl.

martinmestre avatar martinmestre commented on June 28, 2024

Hi, thanks for the answer. I took the example from here, it is this example:
Measurements.derivative.(log1p(x) + y^2 - cos(x/y), [x, y, z])
Am I interpreting something wrongly?
My objective is to use Measurements.jl as a AD tool for functions that depend on unitful quantities.

from measurements.jl.

LebedevRI avatar LebedevRI commented on June 28, 2024

Hm, works for me:

$ julia 
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.2 (2023-07-05)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |

julia> using Measurements

julia> x = 98.1 ± 12.7
98.0 ± 13.0

julia> y = 105.4 ± 25.6
105.0 ± 26.0

julia> z = 78.3 ± 14.1
78.0 ± 14.0

julia> Measurements.derivative(2x - 4y, x)
2.0

julia> Measurements.derivative(2x - 4y, y)
-4.0

julia> Measurements.derivative.(log1p(x) + y^2 - cos(x/y), [x, y, z])
3-element Vector{Float64}:
   0.017700515090289737
 210.7929173496422
   0.0

Perhaps you have too old julia/Measurements package?

from measurements.jl.

LebedevRI avatar LebedevRI commented on June 28, 2024

As it can be seen in
https://github.com/JuliaPhysics/Measurements.jl/blob/55332725ad6826cef711103de7a2413c3b1b1fd6/ext/MeasurementsUnitfulExt.jl
only the main public interface is unit-aware.

from measurements.jl.

martinmestre avatar martinmestre commented on June 28, 2024

Hi. I do not understand which functions are part of the main public interface and which not. Thanks

from measurements.jl.

LebedevRI avatar LebedevRI commented on June 28, 2024

Hi. I do not understand what it means.

The error you are getting is correct, Measurements.jl does not support
calling derivative() with an Unitful arguments, only with Measurements.

from measurements.jl.

martinmestre avatar martinmestre commented on June 28, 2024

I thought that measurements could have units, like

x = (98.1 ± 12.7)u"km"
y = (105.4 ± 25.6)*u"km"

Do you say that derivative() only accepts measurements without units?

from measurements.jl.

LebedevRI avatar LebedevRI commented on June 28, 2024

I thought that measurements could have units, like

x = (98.1 ± 12.7)u"km"
y = (105.4 ± 25.6)*u"km"

Do you say that derivative() only accepts measurements without units?

The thing is that is not a measurement with units,
it's a Measurement-typed value inside of an AbstractUnit-typed value,
and derivative() is missing special-handling to unwrap
the outer AbstractUnit type to get to the actual Measurement inside.

from measurements.jl.

martinmestre avatar martinmestre commented on June 28, 2024

Ok, just to understand, could you give me an example of a "measurement with units" that Measurement.jl understands ?

from measurements.jl.

LebedevRI avatar LebedevRI commented on June 28, 2024

All normal mathematical operations work, only the functionality that is defined in https://github.com/JuliaPhysics/Measurements.jl/blob/c12fb10d3deef0251d671028dfccb3faa9c880dd/src/utils.jl does not.

from measurements.jl.

LebedevRI avatar LebedevRI commented on June 28, 2024

#152 kind-of helps,
but i'm not sure yet how to actually deal with unit mismatch in derivative().

from measurements.jl.

martinmestre avatar martinmestre commented on June 28, 2024

Thank you very much

from measurements.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.