"use strict";
|
/**
|
* @license
|
* Copyright 2017 Google Inc. All Rights Reserved.
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
* you may not use this file except in compliance with the License.
|
* You may obtain a copy of the License at
|
*
|
* http://www.apache.org/licenses/LICENSE-2.0
|
*
|
* Unless required by applicable law or agreed to in writing, software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* See the License for the specific language governing permissions and
|
* limitations under the License.
|
* =============================================================================
|
*/
|
Object.defineProperty(exports, "__esModule", { value: true });
|
var MultinomialProgram = /** @class */ (function () {
|
function MultinomialProgram(batchSize, numOutcomes, numSamples) {
|
this.variableNames = ['probs'];
|
this.outputShape = [batchSize, numSamples];
|
this.userCode = "\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < " + (numOutcomes - 1) + "; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float(" + (numOutcomes - 1) + "));\n }\n ";
|
}
|
MultinomialProgram.prototype.getCustomSetupFunc = function (seed) {
|
var _this = this;
|
return function (gpgpu, webGLProgram) {
|
if (_this.seedLoc == null) {
|
_this.seedLoc = gpgpu.getUniformLocation(webGLProgram, 'seed');
|
}
|
gpgpu.gl.uniform1f(_this.seedLoc, seed);
|
};
|
};
|
return MultinomialProgram;
|
}());
|
exports.MultinomialProgram = MultinomialProgram;
|
//# sourceMappingURL=multinomial_gpu.js.map
|