📄 gy.c
字号:
QccVectorCopy((new_codeword_symbols[codeword_cnt])->vector, codebook->codewords[winners[codeword_cnt]], vector_dimension); } for (codeword_cnt = 0; codeword_cnt < QCCAVQ_GERSHOYANO_NUMUPDATEVECTORS; codeword_cnt++) QccAVQSideInfoCodebookCoder(sideinfo, new_codeword_symbols[codeword_cnt]); if (QccAVQGershoYanoSendSideInfo(sideinfo, new_codeword_symbols, winners)) { QccErrorAddMessage("(QccAVQGershoYanoEncode): Error calling QccAVQGershoYanoSendSideInfo()"); goto QccAVQError; } for (codeword_cnt = 0; codeword_cnt < QCCAVQ_GERSHOYANO_NUMUPDATEVECTORS; codeword_cnt++) QccVectorCopy(codebook->codewords[winners[codeword_cnt]], (new_codeword_symbols[codeword_cnt])->vector, vector_dimension); if (QccVQVectorQuantization(dataset, codebook, distortion, partition, distortion_measure)) { QccErrorAddMessage("(QccAVQGershoYanoEncode): Error calling QccVQVectorQuantization()"); goto QccAVQError; } for (current_vector = 0; current_vector < adaption_interval; current_vector++) channel->channel_symbols[current_vector] = partition[current_vector]; return_value = 0; goto QccAVQExit; QccAVQError: return_value = 1; QccAVQExit: if (partition != NULL) QccFree(partition); if (distortion != NULL) QccVectorFree(distortion); if (partial_distortion != NULL) QccVectorFree(partial_distortion); if (new_codeword_symbols != NULL) { } return(return_value);}int QccAVQGershoYanoDecode(QccDataset *dataset, QccVQCodebook *codebook, QccChannel *channel, QccAVQSideInfo *sideinfo){ int vector_dimension; int block_size; int current_vector; QccAVQSideInfoSymbol *current_symbol = NULL; int address1, address2; if ((dataset == NULL) || (codebook == NULL) || (channel == NULL) || (sideinfo == NULL)) return(0); if (sideinfo->fileptr == NULL) return(0); if ((dataset->vectors == NULL) || (codebook->codewords == NULL) || (channel->channel_symbols == NULL)) return(0); vector_dimension = dataset->vector_dimension; block_size = QccDatasetGetBlockSize(dataset); if ((vector_dimension != codebook->codeword_dimension) || (vector_dimension != sideinfo->vector_dimension)) { QccErrorAddMessage("(QccAVQGershoYanoEncode): Codebook %s, dataset %s, and sideinfo %s", codebook->filename, dataset->filename, sideinfo->filename); QccErrorAddMessage("have different vector dimensions"); goto QccAVQGershoYanoDecodeErr; } if (channel->access_block_size != block_size) { QccErrorAddMessage("(QccAVQGershoYanoDecode): Channel %s must have same block size as dataset %s", channel->filename, dataset->filename); goto QccAVQGershoYanoDecodeErr; } if ((current_symbol = QccAVQSideInfoSymbolReadDesired(sideinfo, QCCAVQSIDEINFO_ADDRESS, NULL)) == NULL) { QccErrorAddMessage("(QccAVQGershoYanoDecode): Error calling QccAVQSideInfoSymbolReadDesired()"); goto QccAVQGershoYanoDecodeErr; } address1 = current_symbol->address; QccAVQSideInfoSymbolFree(current_symbol); if ((current_symbol = QccAVQSideInfoSymbolReadDesired(sideinfo, QCCAVQSIDEINFO_VECTOR, NULL)) == NULL) { QccErrorAddMessage("(QccAVQGershoYanoDecode): Error calling QccAVQSideInfoSymbolReadDesired()"); goto QccAVQGershoYanoDecodeErr; } QccVectorCopy((QccVector)codebook->codewords[address1], current_symbol->vector, vector_dimension); QccAVQSideInfoSymbolFree(current_symbol); if ((current_symbol = QccAVQSideInfoSymbolReadDesired(sideinfo, QCCAVQSIDEINFO_ADDRESS, NULL)) == NULL) { QccErrorAddMessage("(QccAVQGershoYanoDecode): Error calling QccAVQSideInfoSymbolReadDesired()"); goto QccAVQGershoYanoDecodeErr; } address2 = current_symbol->address; QccAVQSideInfoSymbolFree(current_symbol); if ((current_symbol = QccAVQSideInfoSymbolReadDesired(sideinfo, QCCAVQSIDEINFO_VECTOR, NULL)) == NULL) { QccErrorAddMessage("(QccAVQGershoYanoDecode): Error calling QccAVQSideInfoSymbolReadDesired()"); goto QccAVQGershoYanoDecodeErr; } QccVectorCopy((QccVector)codebook->codewords[address2], current_symbol->vector, vector_dimension); for (current_vector = 0; current_vector < block_size; current_vector++) QccVectorCopy(dataset->vectors[current_vector], (QccVector)codebook->codewords [channel->channel_symbols[current_vector]], vector_dimension); if (current_symbol != NULL) QccAVQSideInfoSymbolFree(current_symbol); return(0); QccAVQGershoYanoDecodeErr: if (current_symbol != NULL) QccAVQSideInfoSymbolFree(current_symbol); return(1);}int QccAVQGershoYanoCalcRate(QccChannel *channel, QccAVQSideInfo *sideinfo, FILE *outfile, double *rate, int verbose, int entropy_code_sideinfo){ int return_value; int num_input_vectors; int total_updated; int adaption_interval; int num_adaption_intervals; double channel_entropy; double num_bits_sideinfo; double total_rate, channel_rate, sideinfo_rate; int precision; QccAVQSideInfoSymbol *sideinfo_symbol = NULL; QccChannel sideinfo_address_channel; QccChannel sideinfo_vector_channel; double sideinfo_address_entropy; double sideinfo_vector_entropy; int update, component; if ((outfile == NULL) || (channel == NULL) || (sideinfo == NULL)) return(0); if (QccChannelRemoveNullSymbols(channel)) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccChannelRemoveNullSymbols()"); goto Error; } if ((channel_entropy = QccChannelEntropy(channel, 1)) < 0) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccChannelEntropy()"); goto Error; } if ((sideinfo_symbol = QccAVQSideInfoSymbolAlloc(sideinfo->vector_dimension)) == NULL) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccAVQSideInfoSymbolAlloc()"); goto Error; } num_input_vectors = channel->channel_length; adaption_interval = sideinfo->N; num_adaption_intervals = (int)ceil((double)num_input_vectors / adaption_interval); total_updated = num_adaption_intervals * 2; QccChannelInitialize(&sideinfo_address_channel); sideinfo_address_channel.channel_length = total_updated; sideinfo_address_channel.alphabet_size = channel->alphabet_size; sideinfo_address_channel.access_block_size = QCCCHANNEL_ACCESSWHOLEFILE; if (QccChannelAlloc(&sideinfo_address_channel)) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccChannelAlloc()"); goto Error; } QccChannelInitialize(&sideinfo_vector_channel); sideinfo_vector_channel.channel_length = total_updated * sideinfo->vector_dimension; sideinfo_vector_channel.alphabet_size = sideinfo->codebook_coder.num_levels; sideinfo_vector_channel.access_block_size = QCCCHANNEL_ACCESSWHOLEFILE; if (QccChannelAlloc(&sideinfo_vector_channel)) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccChannelAlloc()"); goto Error; } for (update = 0; update < total_updated; update++) { if (QccAVQSideInfoSymbolReadDesired(sideinfo, QCCAVQSIDEINFO_ADDRESS, sideinfo_symbol) == NULL) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccAVQSideInfoSymbolReadDesired()"); goto Error; } sideinfo_address_channel.channel_symbols[update] = sideinfo_symbol->address; if (QccAVQSideInfoSymbolReadDesired(sideinfo, QCCAVQSIDEINFO_VECTOR, sideinfo_symbol) == NULL) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccAVQSideInfoSymbolReadDesired()"); goto Error; } for (component = 0; component < sideinfo->vector_dimension; component++) sideinfo_vector_channel.channel_symbols[update * sideinfo->vector_dimension + component] = sideinfo_symbol->vector_indices[component]; } if ((sideinfo_address_entropy = QccChannelEntropy(&sideinfo_address_channel, 1)) < 0) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccChannelEntropy()"); goto Error; } if ((sideinfo_vector_entropy = QccChannelEntropy(&sideinfo_vector_channel, 1)) < 0) { QccErrorAddMessage("(QccAVQGershoYanoCalcRate): Error calling QccChannelEntropy()"); goto Error; } if (!entropy_code_sideinfo) { precision = (int)(log((double)sideinfo->codebook_coder.num_levels)/log(2.0) + 0.5); num_bits_sideinfo = total_updated * ((int)(log((double)channel->alphabet_size)/log(2.0) + 0.5) + sideinfo->vector_dimension*precision); } else { num_bits_sideinfo = total_updated * (sideinfo_address_entropy + sideinfo_vector_entropy * sideinfo->vector_dimension); } channel_rate = channel_entropy/sideinfo->vector_dimension; sideinfo_rate = num_bits_sideinfo/num_input_vectors/sideinfo->vector_dimension; total_rate = channel_rate + sideinfo_rate; if (verbose >= 2) { fprintf(outfile, "Rate of the Gersho-Yano algorithm with channel\n %s\n", channel->filename); fprintf(outfile, " and side information\n %s\n", sideinfo->filename); fprintf(outfile, "---------------------------------------------------\n"); fprintf(outfile, " Rate for VQ channel: %f\n", channel_rate); fprintf(outfile, " Rate for side information: %f\n", sideinfo_rate); fprintf(outfile, "\t(%5.2f%% of total rate)\n", QccMathPercent(sideinfo_rate, total_rate)); fprintf(outfile, "---------------------------------------------------\n"); fprintf(outfile, " Overall rate: %f bits per original source symbol\n", total_rate); } else if (verbose == 1) fprintf(outfile, "%f\n", total_rate); if (rate != NULL) *rate = total_rate; return_value = 0; goto Return; Error: return_value = 1; Return: QccChannelFree(&sideinfo_address_channel); QccChannelFree(&sideinfo_vector_channel); return(return_value);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -