Diagnostic BuildDiagnostic( DiagnosticWrap diagnostic_wrap, CXTranslationUnit translation_unit ) { Diagnostic diagnostic; if ( !diagnostic_wrap ) return diagnostic; diagnostic.kind_ = DiagnosticSeverityToType( clang_getDiagnosticSeverity( diagnostic_wrap.get() ) ); // If this is an "ignored" diagnostic, there's no point in continuing since we // won't display those to the user if ( diagnostic.kind_ == INFORMATION ) return diagnostic; CXSourceLocation source_location = clang_getDiagnosticLocation( diagnostic_wrap.get() ); diagnostic.location_ = Location( source_location ); diagnostic.location_extent_ = GetLocationExtent( source_location, translation_unit ); diagnostic.ranges_ = GetRanges( diagnostic_wrap ); diagnostic.text_ = CXStringToString( clang_getDiagnosticSpelling( diagnostic_wrap.get() ) ); diagnostic.long_formatted_text_ = FullDiagnosticText( diagnostic_wrap.get() ); return diagnostic; }
void TextInlineFormat_Underline::ApplyInlineFormat(IDWriteTextLayout* layout) { if (!layout) return; for (const auto& range : GetRanges()) { if (range.length <= 0) continue; layout->SetUnderline(TRUE, range); } }
void TextInlineFormat_Oblique::ApplyInlineFormat(IDWriteTextLayout* layout) { if (!layout) return; for (const auto& range : GetRanges()) { if (range.length <= 0) continue; layout->SetFontStyle(DWRITE_FONT_STYLE_OBLIQUE, range); } }
void TextInlineFormat_Color::ApplyInlineFormat(ID2D1RenderTarget* target, IDWriteTextLayout* layout) { if (!target || !layout) return; Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solidBrush; HRESULT hr = target->CreateSolidColorBrush(ToColorF(m_Color), solidBrush.GetAddressOf()); if (FAILED(hr)) return; for (const auto& range : GetRanges()) { if (range.length <= 0) continue; layout->SetDrawingEffect(solidBrush.Get(), range); } }
void TextInlineFormat_Typography::ApplyInlineFormat(IDWriteTextLayout* layout) { if (!layout) return; for (const auto& range : GetRanges()) { if (range.length <= 0) continue; Microsoft::WRL::ComPtr<IDWriteTypography> typography; HRESULT hr = Canvas::c_DWFactory->CreateTypography(typography.GetAddressOf()); if (FAILED(hr)) continue; DWRITE_FONT_FEATURE feature = { m_Tag, m_Parameter }; hr = typography->AddFontFeature(feature); if (FAILED(hr)) continue; layout->SetTypography(typography.Get(), range); } }
//______________________________________________________________________________ void TFractionFitter::ComputeChisquareLambda() { // Method used internally to compute the likelihood ratio chi2 // See the function GetChisquare() for details if ( !fFitDone ) { Error("ComputeChisquareLambda","Fit not yet (successfully) performed"); fChisquare = 0; return; } // fPlot must be initialized and filled. Leave this to the GetPlot() method. if (! fPlot) GetPlot(); Int_t minX, maxX, minY, maxY, minZ, maxZ; GetRanges(minX, maxX, minY, maxY, minZ, maxZ); Double_t logLyn = 0; // likelihood of prediction Double_t logLmn = 0; // likelihood of data ("true" distribution) for(Int_t x = minX; x <= maxX; x++) { for(Int_t y = minY; y <= maxY; y++) { for(Int_t z = minZ; z <= maxZ; z++) { if (IsExcluded(fData->GetBin(x, y, z))) continue; Double_t di = fData->GetBinContent(x, y, z); Double_t fi = fPlot->GetBinContent(x, y, z); if(fi != 0) logLyn += di * TMath::Log(fi) - fi; if(di != 0) logLmn += di * TMath::Log(di) - di; for(Int_t j = 0; j < fNpar; j++) { Double_t aji = ((TH1*)fMCs.At(j))->GetBinContent(x, y, z); Double_t bji = ((TH1*)fAji.At(j))->GetBinContent(x, y, z); if(bji != 0) logLyn += aji * TMath::Log(bji) - bji; if(aji != 0) logLmn += aji * TMath::Log(aji) - aji; } } } } fChisquare = -2*logLyn + 2*logLmn; return; }
RectList RectList::GetOptimized() const { RectList optimized_rects; RangesList rgl = GetRanges(); for ( RangesList::Iterator iter = rgl.Begin(); !!iter; ++iter ) { Range yr = iter.Key(); int jj = iter.Value().Size(); while ( jj-- ) { Range xr = iter.Value()[jj]; Rect rc( xr.first, yr.first, xr.second-xr.first, yr.second-yr.first ); optimized_rects.push_back(rc); } } return optimized_rects; }
void TextInlineFormat_Shadow::ApplyInlineFormat(ID2D1RenderTarget* target, IDWriteTextLayout* layout, ID2D1SolidColorBrush* solidBrush, const UINT32& strLen, const D2D1_POINT_2F& drawPosition) { if (!target || !layout) return; // In order to make a shadow effect using the built-in D2D effect, we first need to make // certain parts of the string transparent. We then draw only the parts of the string we // we want a shadow for onto a memory bitmap. From this bitmap we can create the shadow // effect and draw it. D2D1_COLOR_F color = D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.0f); Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> transparent; HRESULT hr = target->CreateSolidColorBrush(color, transparent.GetAddressOf()); if (FAILED(hr)) return; // Only change characters outside of the range(s) transparent for (UINT32 i = 0; i < strLen; ++i) { bool found = false; for (const auto& range : GetRanges()) { if (range.length <= 0) continue; if (i >= range.startPosition && i < (range.startPosition + range.length)) { found = true; break; } } if (!found) { DWRITE_TEXT_RANGE temp = { i, 1 }; layout->SetDrawingEffect(transparent.Get(), temp); } } Microsoft::WRL::ComPtr<ID2D1Bitmap> bitmap; Microsoft::WRL::ComPtr<ID2D1BitmapRenderTarget> bTarget; hr = target->CreateCompatibleRenderTarget(bTarget.GetAddressOf()); if (FAILED(hr)) return; // Draw onto memory bitmap target bTarget->BeginDraw(); bTarget->DrawTextLayout(drawPosition, layout, solidBrush); bTarget->EndDraw(); hr = bTarget->GetBitmap(bitmap.GetAddressOf()); if (FAILED(hr)) return; // Shadow effects can only be drawn with a D2D device context Microsoft::WRL::ComPtr<ID2D1DeviceContext> dc; hr = target->QueryInterface(__uuidof(ID2D1DeviceContext), reinterpret_cast<void**>(dc.GetAddressOf())); if (FAILED(hr)) return; // Create shadow effect Microsoft::WRL::ComPtr<ID2D1Effect> shadow; hr = dc->CreateEffect(CLSID_D2D1Shadow, &shadow); if (FAILED(hr)) return; // Load shadow options to effect shadow->SetInput(0, bitmap.Get()); shadow->SetValue(D2D1_SHADOW_PROP_BLUR_STANDARD_DEVIATION, m_Blur); shadow->SetValue(D2D1_SHADOW_PROP_COLOR, ToVector4F(m_Color)); shadow->SetValue(D2D1_SHADOW_PROP_OPTIMIZATION, D2D1_SHADOW_OPTIMIZATION_SPEED); // Draw effect dc->DrawImage(shadow.Get(), m_Offset); }
int main(int argc, char* argv[]) { srand(time(NULL)); std::ifstream in; std::string outName; bool initHarmonies = false; if (argc == 3) { in.open(argv[1]); initHarmonies = in.is_open(); outName = std::string(argv[2]); } int const varCount = GetVarCount(); int const memorySize = 5; float const r_accept = 0.95; float const r_pa = 0.99; float const r_range = 0.1; std::vector<Harmony> init; if (initHarmonies) { for (int i = 0; i < memorySize; ++i) { Harmony h; in.ignore(1); for (int i = 0; i < varCount; ++i) { float weight = 0.0; in >> weight; h.push_back(weight); in.ignore(1); } in.ignore(1); in.ignore(1); init.push_back(h); } } in.close(); int const gameLength = 1000; int const iterationCount = 1000; HarmonyRanges const* ranges = GetRanges(); HarmonyFactory const factory (varCount, *ranges); GeneratedGame generator (gameLength); TetrisPointsEarned f (generator); HarmonyCompareMax maxComp (f); HarmonyCompareWrapper comp (maxComp); HarmonySearch search (comp, factory, varCount, memorySize, r_accept, r_pa, r_range); if (initHarmonies) search.InitializeHarmonies(init); for (int i = 0; i < iterationCount; ++i) { search.Iterate(); generator.GenerateNewGame(); search.EraseHarmonyCaches(); std::cout << "COMPLETED ITERATION " << i << std::endl; } delete ranges; std::vector<Harmony const*> memory; for (int i = 0; i < memorySize; ++i) memory.push_back(search.GetRanked(i)); std::stringstream ss; std::ofstream out (outName.c_str(), std::ios::app); for (int i = 0; i < memorySize; ++i) ss << *(memory.at(i)) << std::endl << std::endl; ss << std::endl; out << ss.str(); out.close(); for (int i = 0; i < memorySize; ++i) delete memory.at(i); std::cout << "Completed!" << std::endl; return 0; }
//______________________________________________________________________________ void TFractionFitter::ComputeFCN(Int_t& /*npar*/, Double_t* /*gin*/, Double_t& f, Double_t* xx, Int_t flag) { // Used internally to compute the likelihood value. // normalise the fit parameters Int_t bin, mc; Int_t minX, maxX, minY, maxY, minZ, maxZ; Int_t x,y,z; GetRanges(minX, maxX, minY, maxY, minZ, maxZ); for (mc = 0; mc < fNpar; ++mc) { Double_t tot; TH1 *h = (TH1*)fMCs[mc]; TH1 *hw = (TH1*)fWeights[mc]; if (hw) { tot = 0; for (z = minZ; z <= maxZ; ++z) { for (y = minY; y <= maxY; ++y) { for (x = minX; x <= maxX; ++x) { if (IsExcluded(fData->GetBin(x, y, z))) continue; Double_t weight = hw->GetBinContent(x, y, z); if (weight <= 0) { Error("ComputeFCN","Invalid weight encountered for MC source %d",mc); return; } tot += weight * h->GetBinContent(x, y, z); } } } } else tot = fIntegralMCs[mc]; fFractions[mc] = xx[mc] * fIntegralData / tot; } if (flag == 3) { TString ts = "Fraction fit to hist: "; ts += fData->GetName(); fPlot = (TH1*) fData->Clone(ts.Data()); fPlot->Reset(); } // likelihood computation Double_t result = 0; for (z = minZ; z <= maxZ; ++z) { for (y = minY; y <= maxY; ++y) { for (x = minX; x <= maxX; ++x) { bin = fData->GetBin(x, y, z); if (IsExcluded(bin)) continue; // Solve for the "predictions" int k0 = 0; Double_t ti = 0.0; Double_t aki = 0.0; FindPrediction(bin, ti, k0, aki); Double_t prediction = 0; for (mc = 0; mc < fNpar; ++mc) { TH1 *h = (TH1*)fMCs[mc]; TH1 *hw = (TH1*)fWeights[mc]; Double_t binPrediction; Double_t binContent = h->GetBinContent(bin); Double_t weight = hw ? hw->GetBinContent(bin) : 1; if (k0 >= 0 && fFractions[mc] == fFractions[k0]) { binPrediction = aki; } else { binPrediction = binContent > 0 ? binContent / (1+weight*fFractions[mc]*ti) : 0; } prediction += fFractions[mc]*weight*binPrediction; result -= binPrediction; if (binContent > 0 && binPrediction > 0) result += binContent*TMath::Log(binPrediction); if (flag == 3) { ((TH1*)fAji.At(mc))->SetBinContent(bin, binPrediction); } } if (flag == 3) { fPlot->SetBinContent(bin, prediction); } result -= prediction; Double_t found = fData->GetBinContent(bin); if (found > 0 && prediction > 0) result += found*TMath::Log(prediction); } } } f = -result; }
//______________________________________________________________________________ void TFractionFitter::CheckConsistency() { // Function used internally to check the consistency between the // various histograms. Checks are performed on nonexistent or empty // histograms, the precise histogram class, and the number of bins. // In addition, integrals over the "allowed" bin ranges are computed. // Any inconsistency results in a error. if (! fData) { Error("CheckConsistency","Nonexistent data histogram"); return; } Int_t minX, maxX, minY, maxY, minZ, maxZ; Int_t x,y,z,par; GetRanges(minX, maxX, minY, maxY, minZ, maxZ); fIntegralData = 0; fNpfits = 0; for (z = minZ; z <= maxZ; ++z) { for (y = minY; y <= maxY; ++y) { for (x = minX; x <= maxX; ++x) { if (IsExcluded(fData->GetBin(x, y, z))) continue; fNpfits++; fIntegralData += fData->GetBinContent(x, y, z); } } } if (fIntegralData <= 0) { Error("CheckConsistency","Empty data histogram"); return; } TClass* cl = fData->Class(); fNDF = fNpfits - fNpar; if (fNpar < 2) { Error("CheckConsistency","Need at least two MC histograms"); return; } for (par = 0; par < fNpar; ++par) { TH1 *h = (TH1*)fMCs.At(par); if (! h) { Error("CheckConsistency","Nonexistent MC histogram for source #%d",par); return; } if ((! h->Class()->InheritsFrom(cl)) || h->GetNbinsX() != fData->GetNbinsX() || (fData->GetDimension() > 1 && h->GetNbinsY() != fData->GetNbinsY()) || (fData->GetDimension() > 2 && h->GetNbinsZ() != fData->GetNbinsZ())) { Error("CheckConsistency","Histogram inconsistency for source #%d",par); return; } fIntegralMCs[par] = 0; for (z = minZ; z <= maxZ; ++z) { for (y = minY; y <= maxY; ++y) { for (x = minX; x <= maxX; ++x) { Int_t bin = fData->GetBin(x, y, z); if (IsExcluded(bin)) continue; Double_t MCEvents = h->GetBinContent(bin); if (MCEvents < 0) { Error("CheckConsistency", "Number of MC events (bin = %d, par = %d) cannot be negative: " " their distribution is binomial (see paper)", bin, par); } fIntegralMCs[par] += MCEvents; } } } if (fIntegralMCs[par] <= 0) { Error("CheckConsistency","Empty MC histogram #%d",par); } } }