how can I interpret this in the ontological graph in protégé:
1 - profile -- hasParameter(domain > range) -> Parameter
2 - serviceParameter -- sParameter (subClass all) -> owl:Thing
How can I describe this in my ontology?
Related
Kindly help me write a simple python program that takes the two roots of a quadratics equation as functions and returns the complete quadratics equation..Sort of reversing the quadratics equation
So, you're given two roots, let's call them a and b.
The math is as follows:
y = (x - a)(x - b)
y = x^2 - (a + b)x + ab
(Note that the right side of the equation can be multiplied by an arbitrary number. There is no way to determine what that number is with the given information.)
Try implementing that and come back here with any questions related to your own code.
Given the following probabilistic context-free grammar -
1.NP -> ADJ N [0.6]
2.NP -> N [0.4]
3.N -> cat [0.2]
4.N -> dog [0.8]
what will be the CNF??
Given PCFG in CNF is given below.
1.NP -> ADJ N [0.6]
2.NP -> cat [0.08]
3.NP -> dog [0.32]
Because you need to get the same probability for the result by applying both the original and the converted set of rules (in CNF).
Be careful! You need to add keep the original rules 3 and 4 with the same probabilities in order for rule 1 to be productive
I am looking for a method in Haskell to format a floating point number in exactly the way described in this (Java) question, for optimal compactness. I think this may also be referred to as "normalization".
I will copy the example scenarios from that question here:
2.80000 -> Should be formatted as "2.8"
765.000000 -> "765" (notice how the decimal point is also dropped)
0.0073943162953 -> "0.00739432" (limit digits of precisionto 6 in this case)
0.0000073943162953 -> "7.39432E-6" (switch to scientific notation if the magnitude is small enoughless than 1E-5 in this case)
7394316295300000 -> "7.39432E+6" (switch to scientific notation if the magnitude is large enoughfor example, when greater than 1E+10)
0.0000073900000000 -> "7.39E-6" (strip trailing zeros from significand in scientific notation)
0.000007299998344 -> "7.3E-6" (rounding from the 6-digit precision limit causes this number to have trailing zeros which are stripped)
Is there a built-in library in Haskell that will do this, or do I have to roll my own?
What you are looking for is formatRealFloat from GHC.Float module. I am not sure if there is documentation available for that module on haskell.org, but here is a summary of the module: http://www.cis.upenn.edu/~bcpierce/courses/advprog/resources/base/GHC.Float.html
You will need to modify it of course to suit your needs, but here is an example:
import GHC.Float
formatFloat :: RealFloat a => a -> String
formatFloat v
| v == 0 = "0"
| abs v < 1e-5 || abs v > 1e10 = formatRealFloat FFExponent Nothing v
| v - fromIntegral (floor v) == 0 = formatRealFloat FFFixed (Just 0) v
| otherwise = formatRealFloat FFGeneric Nothing v
Naturally, it will only work with ghc compiler.
It's been nearly 30 years since I took an Algebra class and I am struggling with some of the concepts in Haskell as I work through Learn you a Haskell. The concept that I am working on now is "recursion". I have watched several youtube videos on the subject and found a site with the arithmetic sequence problem: an = 8 + 3(an-1) which I understand to be an = an-1 + 3 This is what I have in Haskell.
addThree :: (Integral a) => a -> a
addThree 1 = 8
addThree n = (n-1) + 3
Running the script yields:
addThree 1
8
addThree 2
4
addThree 3
6
I am able to solve this and similar recursions on paper, (after polishing much rust), but do not understand the syntax in Haskell.
My Question How do I define the base and the function in Haskell as per my example?
If this is not the place for such questions, kindly direct me to where I should post. I see there are Stack Exchanges for Super User, Programmers, and Mathematics, but not sure which of the Stack family best fits my question.
First a word on Algebra and you problem: I think you are slightly wrong - if we write 3x it usually means 3*x (Mathematicans are even more lazy then programmers) so your series indeed should look like an = 8 + 3*an-1 IMO
Then an is the n-th element in a series of a's: a0, a1, a2, a3, ... that's why you there is a big difference between (n-1) and addThree (n-1) as the last one would designate an-1 while the first one would just be a number not really connected to your series.
Ok, let's have a look at your series an = 8 + 3an-1 (this is how I would understand it - because otherwise you would have x=8+3*x and therefore just x = -4:
you can choose a0 - let's say it`s 0 (as you did?)
then a1=8+3*0 = 8
a2=8+3*8 = 4*8 = 32
a3=8+3*32 = 8+3*32 = 104
...
ok let's say you want to use recursion than the problem directly translates into Haskell:
a :: Integer -> Integer
a 0 = 0
a n = 8 + 3 * a (n-1)
series :: [Integer]
series = map a [0..]
giving you (for the first 5 elements):
λ> take 5 series
[0,8,32,104,320]
Please note that this is a very bad performing way to do it - as the recursive call in a really does the same work over and over again.
A technical way to solve this is to observe that you only need the previous element to get the next one and use Data.List.unfoldr:
series :: [Integer]
series = unfoldr (\ prev -> Just (prev, 8 + 3 * prev)) 0
now of course you can get a lot more fancier with Haskell - for example you can define the series as it is (using Haskells laziness):
series :: [Integer]
series = 0 : map (\ prev -> 8 + 3 * prev) series
and I am sure there are much more ways out there to do it but I hope this will help you along a bit
I have several number-crunching operations that account for a good portion of the CPU time. One example of such operations is this function:
import Data.Number.Erf
import Math.Gamma
import Math.GaussianQuadratureIntegration as GQI
-- Kummer's' "1F1" a.k.a M(a,b,z) Confluent Hypergeometric function
-- Approximation by the Gaussian Quadrature method from 128 up to 1024 points of resolution
kummer :: Double -> Double -> Double -> Double -> Double
kummer a b z err = gammaFactor * integralPart
where
gammaFactor = (gamma b) / (gamma a * gamma (b-a))
integralPart = (integrator err) fun 0 1
fun = (\t -> (e ** (z * t)) * (1-t) ** (b-a-1) * t ** (a-1))
e = exp 1
integrator err
| err > 0.1 = GQI.nIntegrate128
| err > 0.01 = GQI.nIntegrate256
| err > 0.001 = GQI.nIntegrate512
| otherwise = GQI.nIntegrate1024
SO, I was wondering if there are some rules to follow about when a function should be INLINE to improve performance. REPA Authors suggest to:
Add INLINE pragmas to all leaf-functions in your code, especially ones
that compute numeric results. Non-inlined lazy function calls can cost
upwards of 50 cycles each, while each numeric operator only costs one
(or less). Inlining leaf functions also ensures they are specialized
at the appropriate numeric types.
Are these indications also applicable to the rest of the numerical calculations or only to array computations? or is there a more general guide to decide when a function should be inline?
Notice that this post: Is there any reason not to use the INLINABLE pragma for a function? does not address directly the question about if the hints provided by the programmer truly help the compiler to optimize the code.