  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # An algorithm that determines if a function f from the finite set A to the finite set B is an onto function.  » development » An algorithm that determines if a function f from the finite set A to the finite set B is an onto function.

By : spren
Date : November 21 2020, 11:01 PM
like below fixes the issue How can I write an algorithm that determines if a function f from the finite set A to the finite set B is an onto function. , Yeah, that'll work. A potentially easier approach would be code :
``````for each a in A:
remove f(a) from B
return (is B empty?)
`````` ## Idiomatic Python implementation for finite sets, images, and preimages of finite functions?

Date : March 29 2020, 07:55 AM
Hope that helps For arbitrary images from a set to another, I would use a Python dictionary. For example, f(n)=n^2 on a set of {1,2,3,4}, I can do this:
code :
``````preimage = set([1,2,3,4])
mapping = {x: x*x for x in preimage}
image = set(mapping.values())
assert set(mapping.keys()) == preimage
function = lambda x: mapping[x] # so you can now have y = function(x)
check_image = set([function(x) for x in preimage])
assert check_image == image
``````
``````preimage = set([1,2,3,4])
function = lambda x: x*x
image = set([function(x) for x in preimage])
check_preimage = set([y for x in image for y in preimage if function(y)==x])
assert check_preimage == preimage
``````
``````import math
preimage = set([1,2,3,4])
function = lambda x: x*x
inv_func = lambda x: int(math.sqrt(x))
image = set([function(x) for x in preimage])
check_preimage = set([inv_func(x) for x in image])
assert check_preimage == preimage
`````` ## Can anyone please explain difference between finite state machine and finite automata?

By : David
Date : March 29 2020, 07:55 AM
I hope this helps you . Both "Finite State Machine" FSM and "Finite Automata" (or Finite State Automata) FA means same, represents an abstract mathematical model of computation for the class of regular languages.
The word "Finite" significance the presence of the finite amount of memory in the form of the finite number of states Q (read: Finiteness of Regular Language). ## Getting a random transversal for finite family of finite sets

By : shinichi2381
Date : March 29 2020, 07:55 AM
I wish did fix the issue. As Ante observes, we're looking for a bipartite matching, but the hard part here is finding a random one. If your graph is large enough, then you probably have to settle for the rapidly mixing Markov chain of Jerrum and Sinclair. Otherwise, there's an O(2^n poly(n))-time dynamic program for counting maximum matchings (as opposed to the O(n!)-time algorithm for enumerating them), which you can use to sample by repeatedly counting the number of matchings after either using an edge or not to match. ## optim in r :non finite finite difference error

By : Jan Danvill
Date : March 29 2020, 07:55 AM
around this issue The error you ran into is because ϕ becomes negative beyond a certain number of iterations (which indicates that the constraints are not being applied correctly by the algorithm). Also, the solution does not converge to a single value but jumps between a few small values before reaching a situation where the updated covariance matrix is no-longer positive definite. At that stage you get det(v) < 0 and log[det(v)] is undefined. The optim algorithm bails out at that stage.
To see what's happening, play with the maxit and ndeps parameters in the code below. ## MLE error in R: non-finite finite-difference value/ value in 'vmmin' is not finite

By : Grant Redfearn
Date : March 29 2020, 07:55 AM
wish of those help Your Loss variable is negative. In R, raising negative values to a fractional power (i.e. set\$Loss^alpha where alpha is non-integer) returns NaN values. (The only general alternative is to return a complex-valued answer, which you probably don't want.) Did you mean to code Loss as positive rather than negative? Or maybe you want -abs(set\$Loss^alpha) ?
As a general purpose debugging tip, it helps to add 