Skip to content

Commit

Permalink
Merge pull request #177 from Phuire-Research/UI
Browse files Browse the repository at this point in the history
UI
  • Loading branch information
REllEK-IO authored Dec 14, 2023
2 parents 1cd8603 + 420d5b8 commit 47d01e0
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/test/error/random/generateCountingStrategy.strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ActionNode, ActionStrategy, createActionNode, createStrategy } from '../../../model/actionStrategy';
import { counterAdd, counterAddType } from '../../../concepts/counter/qualities/add.quality';
import { counterSubtract } from '../../../concepts/counter/qualities/subtract.quality';

function getRandomRange(min: number, max: number) {
return Math.random() * (max - min) + min;
}

export const generateRandomCountingStrategy = (count: number): [number, ActionStrategy] => {
const length = Math.round(getRandomRange(1, 20));
let numPos = 0;
let numNeg = 0;
let previousStep: ActionNode =
createActionNode(Math.round(getRandomRange(1, 5)) % 2 === 0 ? counterAdd() : counterSubtract(), {
successNode: null,
failureNode: null
});
const stepFirst = previousStep;
if (previousStep.actionType === counterAddType) {
numPos++;
} else {
numNeg++;
}
for (let i = 1; i < length; i++) {
const newStep: ActionNode =
createActionNode(Math.round(getRandomRange(1, 5)) % 2 ? counterAdd() : counterSubtract(), {
successNode: null,
failureNode: null
});
if (newStep.actionType === counterAddType) {
numPos++;
} else {
numNeg++;
}

previousStep.successNode = newStep;
previousStep = newStep;
}
previousStep.successNode = null;

const topic = `Generated Counting Strategy from: ${count}, using ${numPos} Adds and ${numNeg} Subtracts`;
return [
numPos - numNeg,
createStrategy({
initialNode: stepFirst,
topic,
})];
};
59 changes: 59 additions & 0 deletions src/test/error/random/random.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# The Floating Point Error Correction Issue in Graph Computation
Noting that each strategy should be a unique variation within this test. As we are repeating the first step 10 times. Each time we are creating a new strategy. But due to branch prediction, and likewise floating point error correction. This test presents itself as successful. Noting the included log. As if the first iteration is all that runs.
```typescript
const plan = axium.stage('Counting Strategy Stage',
[
(_, dispatch) => {
const [shouldBe, strategy] = generateRandomCountingStrategy(count);
strategyTopic = strategy.topic;
expectedOutput = shouldBe;
totalExpected += expectedOutput;
dispatch(strategyBegin(strategy), {
iterateStage: true,
throttle: 1
});
}, (concepts, dispatch) => {
const axiumState = getAxiumState(concepts);
const counter = selectState<CounterState>(concepts, counterName);
if (axiumState.lastStrategy === strategyTopic && counter) {
console.log('Count: ', counter?.count, 'Topic: ', axiumState.lastStrategy, 'Steps: ', steps, 'Repeating for: ', repeat);
console.log('Expected: ', expectedOutput);
expect(counter.count).toBe(expectedOutput);
if (steps < repeat) {
steps++;
count = counter.count;
dispatch(axiumKick(), {
setStage: 0,
throttle: 1
});
} else {
console.log('Total Expected: ', totalExpected, counter.count);
expect(counter.count).toBe(totalExpected);
setTimeout(() => {done();}, 500);
plan.conclude();
axium.close();
}
}
}
]);
```
The following are the Topics generated upon each iteration, noting each should be unique:
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 0 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 1 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 2 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 3 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 4 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 5 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 6 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 7 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 8 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 9 Repeating for: 10'
* 'Count: -5 Topic: Generated Counting Strategy from: 0, using 1 Adds and 6 Subtracts Steps: 10 Repeating for: 10'

Notice that the steps are increasing. And the strategies are executing as intended, without the count being effected beyond the first successful dispatch. As even if, the same strategy was being dispatched. The count should be going down by 5, upon each successful iteration.

This is noting that within logixUX I have a version of this form of counting that does not experience this same issue. [See this strategy and compare.](https://github.com/Phuire-Research/logixUX/blob/main/server/src/concepts/logixUX/strategies/generateCountingStrategy.strategy.ts). The only change is the placement of the random number generation. Otherwise this is the same strategy.

Therefore, branch prediction in combination with floating point error correction as used within the random number generation process. Is causing a direct hallucination in a program written by hand. This test may vary by computer, but that only serves to demonstrate that this paradigm of computation reveals that we have pushed such to a limit.

Why would the same output be repeated? I do know the reason, but will leave others to attempt to figure out why this might be the case.
51 changes: 51 additions & 0 deletions src/test/error/random/random.renameToTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createAxium, getAxiumState } from '../../../model/axium';
import { strategyBegin } from '../../../model/actionStrategy';
import { selectState } from '../../../model/selector';
import { CounterState, createCounterConcept, countingStrategy, counterName } from '../../../concepts/counter/counter.concept';
import { generateRandomCountingStrategy } from './generateCountingStrategy.strategy';
import { axiumKick } from '../../../concepts/axium/qualities/kick.quality';

test('Axium Counting Strategy Test', (done) => {
const axium = createAxium('axiumStrategyTest', [createCounterConcept()], true, true);
let strategyTopic = '';
let expectedOutput = 0;
let totalExpected = 0;
let count = 0;
const repeat = 10;
let steps = 0;
const plan = axium.stage('Counting Strategy Stage',
[
(_, dispatch) => {
const [shouldBe, strategy] = generateRandomCountingStrategy(count);
strategyTopic = strategy.topic;
expectedOutput = shouldBe;
totalExpected += expectedOutput;
dispatch(strategyBegin(strategy), {
iterateStage: true,
throttle: 1
});
}, (concepts, dispatch) => {
const axiumState = getAxiumState(concepts);
const counter = selectState<CounterState>(concepts, counterName);
if (axiumState.lastStrategy === strategyTopic && counter) {
console.log('Count: ', counter?.count, 'Topic: ', axiumState.lastStrategy, 'Steps: ', steps, 'Repeating for: ', repeat);
console.log('Expected: ', expectedOutput);
expect(counter.count).toBe(expectedOutput);
if (steps < repeat) {
steps++;
count = counter.count;
dispatch(axiumKick(), {
setStage: 0,
throttle: 1
});
} else {
console.log('Total Expected: ', totalExpected, counter.count);
expect(counter.count).toBe(totalExpected);
setTimeout(() => {done();}, 500);
plan.conclude();
axium.close();
}
}
}
]);
});
Loading

0 comments on commit 47d01e0

Please sign in to comment.