I have a sequence -x(-n). I need to calculate dtft from this sequence
According to DTFT properties I x(-n) this is X(e^-jw), but what about -x(-n)? As I understood it should be -X(e^-jw).
Related
So I am trying to replicate a basic MIPS processor, and I was wondering how you would implement comparison instructions? It just doesn't seem to fit in with the rest of the design? I have been reading and apparently the set less than operation in the alu can be used as a comparator, but couldn't you just use a bit-sliced comparator in the alu? What is the implementation of a comparison instruction in a MIPS processor? [https://i.stack.imgur.com/QtX6D.png][1]
One possible way is to use subtraction. The result of the subtraction is compared to zero, basically ORing all bits of the result together, and the sign bit is extracted.
If the two values are equal the result would be zero and zero flag is set and if they are unequal the zero flag is unset. If the first value is less than the second value than the result would be negative and if it is greater than the second value than the result would be not zero and not negative.
Also this comparisons can be combined, e.g. less then or equal is simply a negative result or the zero flag is set. With this it should be possible to implement all comparisons that the MIPS ISA supports.
I need to calculate the number of 1's in a binary number, lets say 5, so 00001001 would be 2 or n=2. I am using MIPS. Best way to do this?
The best way to do this is to count them.
You can check if the least significant bit is set (a 1) by anding it with one. If you get a non-zero result, it was set, so you should increment a counter (that was originally initialised to zero of course).
You can shift all the bits of a value right by using logical shifty operators.
You can loop doing both those operations until your value ends up as zero. There are conditional branch instructions in most architectures.
Your task, then, is to find those instructions for MIPS and put them in the correct order :-)
In no particular order, I'd be looking into the following set of instructions: {andi, srl, beq, addi}, though there may be a few others you'll need.
What formats are used in the WireWorld cellular automata rule (language) for signalling between parts of a pattern (program)?
A single signal that is sent like a pulse, whenever required, traveling through a line of wire cells, containing a signal head followed by a signal tail.
Or a series of signals of a given period (spacing). Commonly, and must be at least, 3. This appears as WTHWTHW etc... The inclusion or lack of each signal in the series represents True or False at each generation or moment in time. Therefore the number of generations that True or False is represented for in this format must be an integer multiple of the period of the series.
A third format uses the number of wire cells between adjacent signals to communicate numbers, this doesn't need a period, as format 2 requires.
Signalling a number can also be achieved through a series of parallel wires, the number is encoded in binary such that each wire represents a part of the number that is twice the value of the previous, see multiplexers and decoders.
Alternatively a large number can be practically represented in a single wire where each signal in a series of signals sequentially represents binary bits through time in the same way. While slower, finite sized circuitry can process calculations such as addition on numbers of an unlimited size.
Less common is a format of my own design for signalling, where True and False may be sent and no signal can be represented by simply not sending any signals, there is also no need for a period. This uses two close adjacent signals for True and a single signal for False. A consequence of this format includes gates that can receive there inputs at any time, creating an output and reseting as soon as both are defined, however circuitry to manage this can be large.
Using HARDSOFTBIGDECIMAL score.
In the config file I set scoreAttained to 0hard/0soft.
I get this error:
Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
at java.math.BigDecimal.divide(Unknown Source)
at org.optaplanner.core.impl.score.buildin.hardsoftbigdecimal.HardSoftBigDecimalScoreDefinition.calculateTimeGradient(HardSoftBigDecimalScoreDefinition.java:96)
at org.optaplanner.core.impl.score.buildin.hardsoftbigdecimal.HardSoftBigDecimalScoreDefinition.calculateTimeGradient(HardSoftBigDecimalScoreDefinition.java:27)
at org.optaplanner.core.impl.termination.ScoreAttainedTermination.calculateSolverTimeGradient(ScoreAttainedTermination.java:50)
at org.optaplanner.core.impl.termination.OrCompositeTermination.calculateSolverTimeGradient(OrCompositeTermination.java:69)
at org.optaplanner.core.impl.termination.OrCompositeTermination.calculateSolverTimeGradient(OrCompositeTermination.java:69)
at org.optaplanner.core.impl.termination.PhaseToSolverTerminationBridge.calculatePhaseTimeGradient(PhaseToSolverTerminationBridge.java:80)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchSolverPhase.solve(DefaultLocalSearchSolverPhase.java:60)
at org.optaplanner.core.impl.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:155)
EDIT:
solved the problem by extending HARDSOFTBIGDECIMALSCOREDEFINITION and overriding calculateTimeGradient(..) method. Here when the divide method is called on BigDecimal, I rounded up.
You are more than likely dividing two numbers that have an exact quotient that is infinite.
For example: 1/3 = 0.33333...
From the docs:
When a MathContext object is supplied with a precision setting of 0
(for example, MathContext.UNLIMITED), arithmetic operations are exact,
as are the arithmetic methods which take no MathContext object. (This
is the only behavior that was supported in releases prior to 5.)
As a corollary of computing the exact result, the rounding mode
setting of a MathContext object with a precision setting of 0 is not
used and thus irrelevant. In the case of divide, the exact quotient
could have an infinitely long decimal expansion; for example, 1
divided by 3.
If the quotient has a nonterminating decimal expansion and the
operation is specified to return an exact result, an
ArithmeticException is thrown. Otherwise, the exact result of the
division is returned, as done for other operations.
So to fix this you need to provide a scale of precision for BigDecimal, like so:
x.divide(y, 2, RoundingMode.HALF_UP)
Where 2 is the precision and RoundingMode.HALF_UP is the rounding mode.
You can read more about rounding here.
Sorry for the difficult question.
I have a large set of sequences to be corrected by either/or adding digits or replacing them (never removing anything) that looks like this:
1,2,,3 => 1,7,4,3
4,,5,6 => 4,4,5,6
4,7,8,9 => 4,7,8,9,1
4,7 => 4,8
4,7,1 => 4,7,2
It starts with a padded original sequence, and a sample correction.
I'd like to be able to work on correcting the sequences automatically by calculating the frequencies of the different n-grams being corrected, the first sample would become
1=>1
2=>7
3=>3
1,2=>1,7
2,3=>7,4,3
1,2,3=>1,7,4,3
I'd collect the frequency of these n-grams corrections, and I'm looking for a way to calculate the best way to correct a new input that may or may not be in the sample data.
This seems to be similar to SMT.
Assign known replacements a score, based on the length of the replacement and the number of occurrences. Naively, I would suggest making this score proportional to the square of the length (longer matches being rarer, in most scenarios I can think of) and the square root of the number of occurrences, such that a 4-item sequence has as much weight as a 2-item sequence that occurs 16 times as often. This would need to be adjusted based on your actual situation.
Given a sequence of length M, there are N substrings of lengths 1 to M, where N=M*(M+1)/2, so if the strings are reasonably short then you could iterate over every substring and look up possible replacements. The number of ways to compose the whole string out of these substrings is also proportional to M^2, I think.
For every possible composition of the original string by substrings, add up the total score of the best (highest score) replacement for each substring.
The composition with the highest total score will be (potentially, given my assumptions about the process) the "best" post-replacement result.