1

I'm new in Julia and want this Python code translated in Julia.

def calcMarkov(preseq,propability,ordnung):
    betrachtungen = 0
    for pos in range(1,len(seq)):
        current = seq[pos]
        fromNode = seq[pos-ordnung:pos]
        if (fromNode == preseq and not current == "X"):
            propability[current] = propability[current] + 1
            betrachtungen += 1
    for key, value in propability.items():
        if(not betrachtungen == 0):
            propability[key] = propability[key]/betrachtungen
    print ("Anzahl der Betrachtungen:",betrachtungen)
    return propability

I Try this:

function calcMarkov(preseq, propability, ordnung)
    betrachtungen = 0
    for pos in 1: length(seq)
        current = seq[pos]
        fromNode = seq[pos-ordnung:pos]
        if fromNode == preseq != current == "X"
            propability[current] = propability[current] + 1
            betrachtungen += 1
        end
        for (key,value) in propability
            if(not betrachtungen == 0)
                propability[key] = propability[key]/betrachtungen
            end
        print("Anzahl der Betrachtungen:",betrachtungen)
        return propability
        end
    end
end

But I get an error message: syntax: missing comma or ) in argument list.

Can you tell me why? I am grateful for any help

B.T
  • 57
  • 5

1 Answers1

6

This line is not correct Julia syntax:

if(not betrachtungen == 0)

You should write:

if betrachtungen != 0

or

if !iszero(betrachtungen)

Even if you fix that there are some other problems:

if (fromNode == preseq and not current == "X"):

is not the same as

if fromNode == preseq != current == "X"

Instead, you should write

if fromNode == preseq && current != "X"

Furthermore:

for pos in range(1,len(seq)):

only iterates from 1 to len(seq)-1 in Python, since ranges are non-inclusive at the end, while

for pos in 1: length(seq)

actually iterates from 1 to length(seq). Perhaps you intended your python code to do this instead?

for pos in range(len(seq)):

This iterates from 0 to len(seq)-1.

Also an extra remark; it is much easier to help you if you can include a minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example

DNF
  • 11,584
  • 1
  • 26
  • 40